﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Newtonsoft.Json;
using Kortex.AllCommandsSpace;
using Kortex.Factory;
using Kortex.Communication_objs;
using Kortex.Container;
using Kortex.Common;
using System.Threading;
using sharpSshTest;
using System.Net.Sockets;
using System.Net;
using System.Globalization;
using System.IO;
using Kortex.Encryption_Dycryption;
using Kortex.WallMgr;
using Kortex.GUI;
using Kortex.KPDabaBase;
using System.Text.RegularExpressions;


namespace Kortex
{
    public partial class KortexGuiMain : Form
    {
        #region Variables
        public CommandHandleKP AllCommands = null;
        string RpcId;
        string RpcId_opState;
        string RpcId_saveAll;
        Thread Color_sensorT;
        bool run = true;
        bool iSconnect = false;
        bool bRecoder = false;
        bool bTrayMiniMaize = true;
        bool bAutoUpdate = true;
        public String localDir = String.Empty;
        String UserType = String.Empty;
        string mFmwVersion = string.Empty;
        
        Dictionary<int, command_requestObj> request_chain = new Dictionary<int, command_requestObj>();
        List<System.Windows.Forms.Button> AdminButtons = new List<Button>();
        List<System.Windows.Forms.Button> UserButtons = new List<Button>();
        List<ReqRespDebugInfo> req_responceDebug = new List<ReqRespDebugInfo>();
        TransctionViewer DebugWindowObj = null;
        Kpdabase kpDb = null;

        #endregion

        #region Start up
        public KortexGuiMain()
        {
            InitializeComponent();


            StartUp();
            


        }
        private void AutoScroingInit()
        {

            this.AutoScroll = true; // For Friends who are running on a low Resolution Monitor

        }
        public void clearTransction()
        {
            req_responceDebug.Clear();
        
        }

        public void ReloadTrasction()
        {
            DebugWindowObj.updateALL(req_responceDebug);
 
        
        }

        public void TransctionViewerClosed()
        {
            DebugWindowObj = null;
        }

       
        private void StartUp()
        {
            AutoScroingInit();
            GlobalLedsInit();
            localDir = Environment.CurrentDirectory;
            AdminButtons.Add(DB_Bid_Mercury_Set);
            AdminButtons.Add(Net_SetMac);
            AdminButtons.Add(Hw_Test_memory_devices_Test_start);
            AdminButtons.Add(Debuf_Encrypt_file);
            AdminButtons.Add(Debuf_Dycrypt_file);
            AdminButtons.Add(Debug_send_receive);
            AdminButtons.Add(Debug_SaveTransctions_butt);
            
            UserButtons.Add(Debug_Start_GenLock);
            UserButtons.Add(Debug_Stop_GenLock);
            UserButtons.Add(Debug_SetGama);
            UserButtons.Add(Debug_Dump_transaction);
            kpDb = Kpdabase.GetInstance(localDir + "\\cubeDB");

            try
            {
                if (kpDb.GetWallMgr_table_val("SendToTrayCube").ToLower() == "false")
                {
                    System_tran_COntrol_tip.ToolTipTitle = "off";
                    bTrayMiniMaize = false;
                    System_tray_minimazer_Led.Color = Color.Gray;
                }
                else
                {
                    System_tran_COntrol_tip.ToolTipTitle = "on";
                    bTrayMiniMaize = true;
                    System_tray_minimazer_Led.Color = Color.PaleGreen;
                    
                }
                

            }
            catch (Exception e)
            { }

            
            
            

             FileInfo MyFile = new FileInfo(localDir+"\\IpAddress.txt");
             if (MyFile.Exists)
             {
                 FileStream FStream = null;
                 FStream = File.OpenRead(localDir + "\\IpAddress.txt");
                 int count = 0;
                 byte[] Buff = new Byte[FStream.Length];
                 count = FStream.Read(Buff, 0, (Int32)FStream.Length);
                 FStream.Close();
                 string AllIps = System.Text.ASCIIEncoding.ASCII.GetString(Buff);
                 string[] AdIp = AllIps.Split("|".ToCharArray());
                 txtBox_IP.Text = AdIp[0];

                 for (int i = 0; i < AdIp.Length; i++)
                 {
                     if (AdIp[i] != "")
                     txtBox_IP.Items.Add(AdIp[i]);
                 }

             }
        
        }

       
        private void KortexGuiMain_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
            Kortex.Factory.Factory.CreateAll(this);
            
        }
        #endregion

        #region Responce Mgr

        public void UpdateDebugInfo(ReqRespDebugInfo json)
        {

            if (bRecoder)
            {
                Monitor.Enter(req_responceDebug);
                req_responceDebug.Add(json);
                Monitor.Exit(req_responceDebug);

                if (DebugWindowObj != null)
                {
                    DebugWindowObj.update(json);
                }
            }

        
        }
        public void Responce(string str)
        {

           // MessageBox.Show(str);
            
        }

        
        private void GetUpdateResult(command_requestObj req,General_responce res,string rpcID)
        {
            int id;
            if(rpcID != null)
                RpcId = rpcID;
            
            if(res.result.taskStatus != null)
            if (res.result.taskStatus.ToLower() == "success")
            {
                Gen_Fmw_updare_result_show.Text = res.result.taskStatus;
                Gen_Fmw_updare_result_show.BackColor = Color.GreenYellow;
                return;
            }
            else
                Gen_Fmw_updare_result_show.Text = res.result.taskStatus;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "taskidnotfound" || res.result.taskStatus.ToLower() == "fail") return;

            Thread.Sleep(2000);
            Gen_Fmw_updare_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_fmw_update_status_get, Gen_Fmw_updare_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.Getfmw_update_status(RpcId);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        
        }

        private void RebootCube()
        {
            int id;
            if (CheckFmwVersion() >= 0.54)
            {

                Set_Op_state_show.BackColor = Color.HotPink;
                command_requestObj obj = new command_requestObj(Common.commandType.cmd_gen_operation_state_set, Set_Op_state_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetOperationState("reboot");
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
            }
            else
            {
                Set_Op_state_show.BackColor = Color.HotPink;
                command_requestObj obj = new command_requestObj(Common.commandType.cmd_gen_reboot_set, Set_Op_state_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetReboot();
                request_chain[id] = obj;
                Monitor.Exit(request_chain);


            }
        
        }
        private void GetUpdateRebootResult(command_requestObj req, General_responce res, string rpcID)
        {
            int id;
            if (rpcID != null)
                RpcId = rpcID;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "success")
                {
                    RebootCube();
                    return;
                }
                else
                    Gen_Fmw_updare_result_show.Text = res.result.taskStatus;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "taskidnotfound" || res.result.taskStatus.ToLower() == "fail")
                {
                    RebootCube();
                    return;
                }

            Thread.Sleep(2000);
            Gen_Fmw_updare_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_fmw_update_reboot_status_get, Gen_Fmw_updare_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.Getfmw_update_status(RpcId);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void GetGamaUpdateResult(command_requestObj req, General_responce res, string rpcID)
        {
            int id;
            if (rpcID != null)
                RpcId = rpcID;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "success")
                {
                    textBox182.Text = res.result.taskStatus;
                    textBox182.BackColor = Color.GreenYellow;
                    return;
                }
                else
                    textBox182.Text = res.result.taskStatus;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "taskidnotfound" || res.result.taskStatus.ToLower() == "fail") return;

            //Thread.Sleep(2000);
            Delay(2000);
            textBox182.BackColor = Color.HotPink;
            textBox182.Text = res.result.taskStatus;
            
            //textBox177.BackColor = Color.GreenYellow;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_barco_gama_set_update_status, textBox182);
            Monitor.Enter(request_chain);
            id = AllCommands.Getfmw_update_status(RpcId);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        # region delay

        void Delay(int ms)
        {
            int time = Environment.TickCount;

            while (true)
                if (Environment.TickCount - time >= ms) return;

        }


        #endregion      

        private void GettiggerDiagnosticsResult(command_requestObj req, General_responce res, string rpcID)
        {
            int id;
            if (rpcID != null)
                RpcId = rpcID;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "success")
                {
                    textBox177.Text = res.result.taskStatus;
                    textBox177.BackColor = Color.GreenYellow;
                    GetDiagnostics_count();
                    return;
                }
                else
                    textBox177.Text = res.result.taskStatus;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "taskidnotfound" || res.result.taskStatus.ToLower() == "fail") return;

            //Thread.Sleep(2000);
            //Delay(2000);
            textBox177.BackColor = Color.HotPink;
            textBox177.Text = res.result.taskStatus;
            
            //textBox177.BackColor = Color.GreenYellow;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_tigger_Diagnostics_status_get, textBox182);
            Monitor.Enter(request_chain);
            id = AllCommands.Getfmw_update_status(RpcId);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }


        private void GetSaveAllResult(command_requestObj req, General_responce res, string rpcID)
        {
            int id;
            if (rpcID != null)
                RpcId_saveAll = rpcID;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "success")
                {
                    DB_saveAll_result_show.Text = res.result.taskStatus;
                    DB_saveAll_result_show.BackColor = Color.GreenYellow;
                    return;
                }
                else
                    DB_saveAll_result_show.Text = res.result.taskStatus;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "taskidnotfound" || res.result.taskStatus.ToLower() == "fail") return;

           

            


            Thread.Sleep(500);
            Set_Op_state_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_dataBase_saveAll_internl, Set_Op_state_show);
            Monitor.Enter(request_chain);
            id = AllCommands.Getfmw_update_status(RpcId_saveAll);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void GetOperationStateResult(command_requestObj req, General_responce res, string rpcID)
        {
            int id;
            if (rpcID != null)
                RpcId_opState = rpcID;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "success")
                {
                    Set_Op_state_show.Text = res.result.taskStatus;
                    Set_Op_state_show.BackColor = Color.GreenYellow;
                    return;
                }
                else
                    Set_Op_state_show.Text = res.result.taskStatus;

            if (res.result.taskStatus != null)
                if (res.result.taskStatus.ToLower() == "taskidnotfound" || res.result.taskStatus.ToLower() == "fail") return;

            if (Gen_Op_state_combo.Text == "standby" || Gen_Op_state_combo.Text == "reboot")
            {
                DisConnect_Click(null, null);
                return;
            }

            Thread.Sleep(500);
            Set_Op_state_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_gen_operation_state_set_internal, Set_Op_state_show);
            Monitor.Enter(request_chain);
            if (RpcId_opState != null)
            {
                id = AllCommands.Getfmw_update_status(RpcId_opState);
                request_chain[id] = obj;
            }
            Monitor.Exit(request_chain);

        }

        private void SetColorPickerPanelBgCOlor(string colr,int r,int g,int b)
        {
            switch (colr)
            {
                case "red":
                    Img_Color_picker_show_panel.BackColor = Color.Red;
                    break;
                case "green":
                    Img_Color_picker_show_panel.BackColor = Color.Green;
                    break;
                case "white":
                    Img_Color_picker_show_panel.BackColor = Color.White;
                    break;
                case "blue":
                    Img_Color_picker_show_panel.BackColor = Color.Blue;
                    break;
                case "cyan":
                    Img_Color_picker_show_panel.BackColor = Color.Cyan;
                    break;
                case "magenta":
                    Img_Color_picker_show_panel.BackColor = Color.Magenta;
                    break;

                case "yellow":
                    Img_Color_picker_show_panel.BackColor = Color.Yellow;
                    break;
                case "custom":
                    Color clr = Color.FromArgb(r, g, b);
                    Img_Color_picker_show_panel.BackColor = clr;
                    break;
            }


        
        }

           private void GetLogFile(command_requestObj req,General_responce res)
            {
                int id;

                if (res.result.count != null)
                {
                    req.MsgCount = Convert.ToInt32(res.result.count);
                    req.linenum = 1;
                
                }

                textBox174.BackColor = Color.HotPink;
                GuiBoxArray gui = null;
                //gui.Add(textBox155, textBox154, textBox153);
                command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_get_log_msg_internal, textBox174, gui);
                obj.linenum = (req.linenum+1);
                Monitor.Enter(request_chain);
                id = AllCommands.GetLogMessage(req.linenum.ToString());
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
    
            }

           private void GetLogFileOf_diagnostics(command_requestObj req, General_responce res)
           {
               int id;

               if (res.result.count != null)
               {
                   req.MsgCount = Convert.ToInt32(res.result.count);
                   req.linenum = 1;

               }

               textBox177.BackColor = Color.HotPink;
               GuiBoxArray gui = null;
               //gui.Add(textBox155, textBox154, textBox153);
               command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_Get_Diagnostics_msgs_get, textBox177, gui);
               obj.linenum = (req.linenum + 1);
               Monitor.Enter(request_chain);
               id = AllCommands.GetDianosticMessage(req.linenum.ToString());
               request_chain[id] = obj;
               Monitor.Exit(request_chain);

           }

           private void ConnectRemainingServices(double ver)
           {
               ConnectCube();
 
           
           }

           private void Kp_Show()
           {


               OpenFileDialog openFileDialogkp = new OpenFileDialog();
                openFileDialogkp.Title = "kp";
                openFileDialogkp.ShowDialog();


/*
openFileDialog.InitialDirectory = $InitialDirectory
openFileDialog.Filter = $Filter
if ($AllowMultiSelect) { $openFileDialog.MultiSelect = $true }
$openFileDialog.ShowHelp = $true
$openFileDialog.ShowDialog() | out-null
if ($AllowMultiSelect) { return $openFileDialog.Filenames } else { return $openFileDialog.Filename }
}
  */         
           }

           private void upGradeToLatest()
           {

               DialogResult ret = MessageBox.Show("Current version of OVD/KVD firmware does not support failsafe upgrade mechanism,Please ensure that power to panel is not interrupted during this 3 minutes of upgrade time(curretly SPI Raw mode supported) .Do you want to continue?", "WARNING!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

               if (ret != System.Windows.Forms.DialogResult.Yes)
               {
                   DisConnect_Click(null, null);
                   return;

               }

               //Thread.CurrentThread.SetApartmentState (ApartmentState.STA); 

              // Kp_Show();
               ret = openFileDialog1.ShowDialog();

               if (ret != System.Windows.Forms.DialogResult.OK)
               {
                   DisConnect_Click(null, null);
                   return;

               }


               Kortex_gui_controls_tab.Enabled = false;

               int id;
               Gen_Fmw_updare_result_show.BackColor = Color.HotPink;
               string BankInfo = string.Empty;
               string dyKI = GetDyki();
               command_requestObj obj = new command_requestObj(Common.commandType.cmd_fmw_update_reboot_spi, Gen_Fmw_updare_result_show);

               if (openFileDialog1.FileName != "")
                   KpScpSshclt.kp_scp(txtBox_IP.Text, openFileDialog1.FileName, "/tmp/fmwUpdate.bin", dyKI);


               Monitor.Enter(request_chain);
               id = AllCommands.updateFirmware("MrcSpiImg", "/tmp/fmwUpdate.bin", BankInfo);
               request_chain[id] = obj;
               Monitor.Exit(request_chain);


 
           
           }
           private void Apply_version_policy_at_connect(double ver)
           {
               if (ver >= 1.0)
               {
                   ConnectRemainingServices(ver);
                   return;
               }


               //MessageBox.Show("Old Firmware found!! connecting partially to fecilitate upgrade to latest version", "WARNING!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
               DialogResult ret =  MessageBox.Show("Old Firmware found!! With this version of GUI you can only upgrade this cube to latest.", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);

               /*if (ret != System.Windows.Forms.DialogResult.Yes)
               {
                   DisConnect_Click(null, null);
                   return;
               
               }
                * */

               Connect.Enabled = false;
               DisConnect.Enabled = true;
               /*Kortex_control_Picture_tab.en
                Kortex_control_Image_tab
                Kortex_control_montering_tab
                DataBaseD
                Networking
                FMW
                Col_Sensor_tab
                tabPage1
               */
               //upGradeToLatest();

           
           }

        private void handle_result(command_requestObj req,General_responce res)
        {
            
            switch (req.cmdType)
            {

                //cmd_mrc_spi_module_version_at_connect_get

                case commandType.cmd_mrc_spi_module_version_at_connect_get:

                    if (res.result.version != null)
                    {
                        fmw_veraion_L.Text = "FMW ver:" + res.result.version;
                        mFmwVersion = res.result.version;
                        Apply_version_policy_at_connect(CheckFmwVersion());
                    }

                    break;
                case commandType.cmd_mo_get_log_msg_internal:
                    if (res.result.message != null)
                    {
                        GetLogFile(req, res);
                        MO_LogMessages_richBox.AppendText(res.result.message);
                    }


                    break;
                case commandType.cmd_mo_Get_Diagnostics_msgs_get:
                    if (res.result.message != null)
                    {
                       // Delay(100);
                        GetLogFileOf_diagnostics(req, res);
                        MO_DiagnosticsMessages_richBox.AppendText(res.result.message);
                    }
                    break;
                case commandType.cmd_img_clock_status_get:
                    if (res.result.clkstatus != null)
                        req.guiVal.TextBoxs[0].Text = res.result.clkstatus;
                    break;
                case commandType.cmd_img_wall_config_status_get:

                    if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.x.ToString();

                    
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[1].Text = res.result.y.ToString();

                    
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[2].Text = res.result.max_x.ToString();

                    
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[3].Text = res.result.max_y.ToString();

                        if (req.guiVal.TextBoxs != null)
                            if (res.result.mode != null)
                                req.guiVal.TextBoxs[4].Text = res.result.mode;

                        if (req.guiVal.TextBoxs != null)
                            if (res.result.input != null)
                                req.guiVal.TextBoxs[5].Text = res.result.input;
                            


                    break;
                case commandType.cmd_img_scm_status_get:
                    if (res.result.scmstatus != null)
                        req.guiVal.TextBoxs[0].Text = res.result.scmstatus;
                    break;
                case commandType.cmd_cs_gaam_upload_status_get:
                    if (res.result.status != null)
                        req.guiVal.TextBoxs[0].Text = res.result.status;

                    break;
                case commandType.cmd_mo_get_fan_ticks:
                    if (res.result.ticks != null)
                        req.guiVal.TextBoxs[0].Text = res.result.ticks;

                    break;
                case commandType.cmd_mo_Get_Diagnostics_count_get:
                   // Delay(100);
                    if (res.result.count != null)
                        GetLogFileOf_diagnostics(req, res);

                    break;
                case commandType.cmd_mo_tigger_Diagnostics_status_get:
                case commandType.cmd_mo_tigger_Diagnostics:
                    //Delay(200);

                    GettiggerDiagnosticsResult(req, res, res.result.taskId);

                    break;
                case commandType.cmd_mo_get_log_msg_count_internal:
                    //Delay(100);
                    if (res.result.count != null)
                    GetLogFile(req, res);
                    break;
                case commandType.cmd_cs_barco_gama_set:
                case commandType.cmd_cs_barco_gama_set_update_status:
                    GetGamaUpdateResult(req, res, res.result.taskId);
                    break;
                case commandType.cmd_cs_gobal_error_info_get:
                    if (res.result.colorOutOfTolerance != null)
                        req.guiVal.TextBoxs[0].Text = res.result.colorOutOfTolerance;
                    if (res.result.colorNotReachable != null)
                        req.guiVal.TextBoxs[1].Text = res.result.colorNotReachable;
                    if (res.result.brightnessNotReachable != null)
                        req.guiVal.TextBoxs[2].Text = res.result.brightnessNotReachable;
                    if (res.result.spectralCalibMissing != null)
                        req.guiVal.TextBoxs[3].Text = res.result.spectralCalibMissing;
                    if (res.result.sensorState != null)
                        req.guiVal.TextBoxs[4].Text = res.result.sensorState;
                    

                    break;
                case commandType.cmd_cs_max_min_brightness_get:
               
                        req.guiVal.TextBoxs[0].Text = res.result.min_brightness.ToString();
                        req.guiVal.TextBoxs[1].Text = res.result.max_brightness.ToString();


                    break;
                case commandType.cmd_cs_black_level_get:
                case commandType.cmd_cs_white_level_get:

                    if (res.result.value != null)
                    req.guiVal.TextBoxs[0].Text = res.result.value;
                    
                    break;

                case commandType.cmd_cs_cbm_mode_params_get:
                    req.guiVal.TextBoxs[0].Text = res.result.backlight.ToString();
                    req.guiVal.TextBoxs[1].Text = res.result.rOffset.ToString();
                    req.guiVal.TextBoxs[2].Text = res.result.gOffset.ToString();
                    req.guiVal.TextBoxs[3].Text = res.result.bOffset.ToString();
                    req.guiVal.TextBoxs[4].Text = res.result.rGain.ToString();
                    req.guiVal.TextBoxs[5].Text = res.result.gGain.ToString();
                    req.guiVal.TextBoxs[6].Text = res.result.bGain.ToString();
                    break;
                case commandType.cmd_cs_cbm_mode_get:

                    if (res.result.mode != null)
                        req.guiVal.ComboBoxs[0].Text = res.result.mode;
                    
                    break;

                case commandType.cmd_cs_white_banance_get:
                    req.guiVal.TextBoxs[0].Text = res.result.delta_x.ToString();
                    req.guiVal.TextBoxs[1].Text = res.result.delta_y.ToString();
                    req.guiVal.TextBoxs[2].Text = res.result.delta_Y.ToString();
                    break;

                case commandType.cmd_cs_user_target_control_params_get:
                    //opsCOntrolPanel1.StopBlink(1);
                        textBox158.Text = res.result.colortemp.ToString();
                        textBox157.Text = res.result.locusOffset.ToString();

                        if (res.result.gammaFactor != null)
                            cs_UTP_GaamaFacrot_Combo.Text = res.result.gammaFactor;

                    textBox152.Text = res.result.brightness.ToString();
                   textBox151.Text = res.result.target_x.ToString();
                    textBox150.Text = res.result.target_y.ToString();


                    break;
                case commandType.cmd_cs_Calibrated_XYZ_get:
                    req.guiVal.TextBoxs[0].Text = res.result.X.ToString();
                    req.guiVal.TextBoxs[1].Text = res.result.Y.ToString();
                    req.guiVal.TextBoxs[2].Text = res.result.Z.ToString();

                    break;
                case commandType.cmd_ops_operationt_set:
                    Thread.Sleep(2000);
                    Ops_Control_Panel_refresh_Click(null, null);

                break;

                case commandType.cmd_dataBase_saveAll:
                        GetSaveAllResult(req,res,res.result.taskId);
                    break;
                case commandType.cmd_dataBase_saveAll_internl:
                    GetSaveAllResult(req, res, res.result.taskId);
                    break;

                case commandType.cmd_img_errors_get:
                    //opsCOntrolPanel1.StopBlink(1);

                    if (res.result.wallCfgerror != null)
                        req.guiVal.TextBoxs[0].Text = res.result.wallCfgerror;

                    if (res.result.bypass_error != null)
                        req.guiVal.TextBoxs[1].Text = res.result.bypass_error;
                    break;

                //

                case commandType.cmd_net_NetInfo_get:
                    //opsCOntrolPanel1.StopBlink(1);

                    if (res.result.mac != null)
                        req.guiVal.TextBoxs[0].Text = res.result.mac;
                    
                    if (res.result.ip != null)
                        req.guiVal.TextBoxs[1].Text = res.result.ip;

                    if (res.result.netmask != null)
                        req.guiVal.TextBoxs[2].Text = res.result.netmask;

                    break;
                case commandType.cmd_net_networkIf_get:
                    //opsCOntrolPanel1.StopBlink(1);

                    if (res.result.ip != null)
                        req.guiVal.TextBoxs[0].Text = res.result.ip;

                    if (res.result.netmask != null)
                        req.guiVal.TextBoxs[1].Text = res.result.netmask;

                    if (res.result.addressing != null)
                        Net_GetSetNetIf_Mode_combo.Text = res.result.addressing;

                       

                    break;

                case commandType.cmd_cs_params_get:
                        req.guiVal.ComboBoxs[0].Text = res.result.gain.ToString();
                        req.guiVal.ComboBoxs[1].Text = res.result.prescale.ToString();

                        if (res.result.period != null)
                            req.guiVal.ComboBoxs[2].Text = res.result.period;
                        if (res.result.pulses != null)
                            req.guiVal.ComboBoxs[3].Text = res.result.pulses;
                    
                    break;

                case commandType.cmd_cs_field_calib_get:
                case commandType.cmd_cs_factory_calib_get:
                    
                        req.guiVal.TextBoxs[0].Text = res.result.red_X.ToString();
                        req.guiVal.TextBoxs[1].Text = res.result.red_Y.ToString();
                        req.guiVal.TextBoxs[2].Text = res.result.red_Z.ToString();
                        req.guiVal.TextBoxs[3].Text = res.result.green_X.ToString();
                        req.guiVal.TextBoxs[4].Text = res.result.green_Y.ToString();
                        req.guiVal.TextBoxs[5].Text = res.result.green_Z.ToString();
                        req.guiVal.TextBoxs[6].Text = res.result.blue_X.ToString();
                        req.guiVal.TextBoxs[7].Text = res.result.blue_Y.ToString();
                        req.guiVal.TextBoxs[8].Text = res.result.blue_Z.ToString();

                    break;



                case commandType.cmd_cs_int_field_ref_data_get:
                case commandType.cmd_cs_int_factory_ref_data_get:

                    req.guiVal.TextBoxs[0].Text = res.result.red_0.ToString();
                    req.guiVal.TextBoxs[1].Text = res.result.green_0.ToString();
                    req.guiVal.TextBoxs[2].Text = res.result.blue_0.ToString();
                    req.guiVal.TextBoxs[3].Text = res.result.red_1.ToString();
                    req.guiVal.TextBoxs[4].Text = res.result.green_1.ToString();
                    req.guiVal.TextBoxs[5].Text = res.result.blue_1.ToString();

                    break;

                case commandType.cmd_cs_ext_field_ref_data_get:
                case commandType.cmd_cs_ext_factory_ref_data_get:


                    if (res.result.timestamp != null)
                        req.guiVal.TextBoxs[0].Text = res.result.timestamp;
                    if (res.result.proddata != null)
                        req.guiVal.TextBoxs[1].Text = res.result.proddata;
                    if (res.result.processVer != null)
                        req.guiVal.TextBoxs[2].Text = res.result.processVer;
                    
                    req.guiVal.TextBoxs[3].Text = res.result.red_X.ToString();
                    req.guiVal.TextBoxs[4].Text = res.result.red_Y.ToString();
                    req.guiVal.TextBoxs[5].Text = res.result.red_Z.ToString();
                    req.guiVal.TextBoxs[6].Text = res.result.green_X.ToString();
                    req.guiVal.TextBoxs[7].Text = res.result.green_Y.ToString();
                    req.guiVal.TextBoxs[8].Text = res.result.green_Z.ToString();
                    req.guiVal.TextBoxs[9].Text = res.result.blue_X.ToString();
                    req.guiVal.TextBoxs[10].Text = res.result.blue_Y.ToString();
                    req.guiVal.TextBoxs[11].Text = res.result.blue_Z.ToString();

                    break;
                case commandType.cmd_cs_raw_mes_cis_get:
                case commandType.cmd_cs_backlight_mes_get:
                case commandType.cmd_cs_backlight_mes_update_get:
                case commandType.cmd_cs_raw_count_get:
                    //opsCOntrolPanel1.StopBlink(1);

                    if (res.result.cs_resp0 != null)
                        req.guiVal.TextBoxs[0].Text = res.result.cs_resp0;
                    if (res.result.cs_resp1 != null)
                        req.guiVal.TextBoxs[1].Text = res.result.cs_resp1;
                    if (res.result.red_0 != null)
                        req.guiVal.TextBoxs[2].Text = res.result.red_0;
                    if (res.result.green_0 != null)
                        req.guiVal.TextBoxs[3].Text = res.result.green_0;
                    if (res.result.blue_0 != null)
                        req.guiVal.TextBoxs[4].Text = res.result.blue_0;
                    if (res.result.white_0 != null)
                        req.guiVal.TextBoxs[5].Text = res.result.white_0;
                    if (res.result.red_1 != null)
                        req.guiVal.TextBoxs[6].Text = res.result.red_1;
                    if (res.result.green_1 != null)
                        req.guiVal.TextBoxs[7].Text = res.result.green_1;
                    if (res.result.blue_1 != null)
                        req.guiVal.TextBoxs[8].Text = res.result.blue_1;
                    if (res.result.white_1 != null)
                        req.guiVal.TextBoxs[9].Text = res.result.white_1;

                        

                    break;
                case commandType.cmd_ops_power_state_get:
                    //opsCOntrolPanel1.StopBlink(1);

                    if(res.result.state != null)
                        opsCOntrolPanel1.SetToolTipTitle( res.result.state,1);

                    if (res.result.state == "off")
                        opsCOntrolPanel1.SetColor(Color.Gray, 1);
                    else
                        opsCOntrolPanel1.SetColor(Color.GreenYellow, 1);

                    break;
                case commandType.cmd_ops_fan_state_get:
                   // opsCOntrolPanel1.StopBlink(2);

                    if (res.result.state != null)
                        opsCOntrolPanel1.SetToolTipTitle(res.result.state, 2);
                          if (res.result.state == "off")
                        opsCOntrolPanel1.SetColor(Color.Gray, 2);
                    else
                        opsCOntrolPanel1.SetColor(Color.GreenYellow, 2);

                    break;

                case commandType.cmd_ops_plug_state_get:
                   // opsCOntrolPanel1.StopBlink(3);

                    if (res.result.state != null)
                        opsCOntrolPanel1.SetToolTipTitle(res.result.state, 3);

                    if (res.result.state.ToLower() == "unplugged")
                        opsCOntrolPanel1.SetColor(Color.Gray, 3);
                    else
                        opsCOntrolPanel1.SetColor(Color.GreenYellow, 3);

                    break;
                case commandType.cmd_ops_operationt_get:
                    if (req.guiVal.ComboBoxs != null)
                        if (res.result.state != null)
                            req.guiVal.ComboBoxs[0].Text = res.result.state;
                    break;
                case commandType.cmd_img_video_byPass_get:

                    if (req.guiVal.ComboBoxs != null)
                         if (res.result.cmd != null)
                            req.guiVal.ComboBoxs[0].Text = res.result.cmd;
                    break;

                case commandType.cmd_img_pattern_type_get:

                    if (res.result.pattern != null)
                        req.guiVal.ComboBoxs[0].Text = res.result.pattern;

                    break;
                case commandType.cmd_img_input_timing_get:

                    if (req.guiVal.TextBoxs != null)
                    {

                        if(res.result.h_active != null)
                        req.guiVal.TextBoxs[0].Text = res.result.h_active;
                        if (res.result.v_active != null)
                        req.guiVal.TextBoxs[1].Text = res.result.v_active;
                        if (res.result.frame_rate != null)
                        req.guiVal.TextBoxs[2].Text = res.result.frame_rate;
                        if (res.result.pixel_clock != null)
                        req.guiVal.TextBoxs[3].Text = res.result.pixel_clock;
                    }

                    break;

                case commandType.cmd_fmw_mstar_version_get:

                    if (req.guiVal.TextBoxs != null)
                        if (res.result.@string != null)
                        req.guiVal.TextBoxs[0].Text = res.result.@string.ToString();

                    break;


                case commandType.cmd_gen_operation_power_off_set:
                    DisConnect_Click(null, null);
                    break;
                case commandType.cmd_img_background_get:

                    if (res.result.bkgnd == "custom")
                    {
                        if (req.guiVal.TextBoxs != null)
                        {
                            req.guiVal.TextBoxs[0].Text = res.result.red.ToString();
                            req.guiVal.TextBoxs[1].Text = res.result.green.ToString();
                            req.guiVal.TextBoxs[2].Text = res.result.blue.ToString();
                        }
                    }

                    img_background_combo.Text = res.result.bkgnd;
                    SetColorPickerPanelBgCOlor(res.result.bkgnd, res.result.red, res.result.green, res.result.blue);
                    /*if (res.result.bkgnd == "custom")
                        Img_Color_GroupBox.Visible = true;
                    */
                    break;

                case commandType.cmd_img_wallConfig_get:

                    if (req.guiVal.ComboBoxs != null)
                        req.guiVal.ComboBoxs[0].Text = res.result.mode;
                    break;

                case commandType.cmd_img_wallConfig_state_get:

                    if (req.guiVal.TextBoxs != null)
                        req.guiVal.TextBoxs[0].Text = res.result.state;

                    if (res.result.state == "on")
                        img_WallGeo_Enable_ON_radio.Checked = true;
                    else
                        img_WallGeo_Enable_Off_radio.Checked = true;

                    break;

                case commandType.cmd_img_wallGeometry_get:
                    
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.x.ToString();

                    
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[1].Text = res.result.y.ToString();

                    
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[2].Text = res.result.max_x.ToString();

                    
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[3].Text = res.result.max_y.ToString();

                            //img_WallGeoMetry_input.Text = res.result.input;
                            img_WallGeoMetry_Mode.Text = res.result.mode;

                    break;

                //

                case commandType.cmd_AutoSave_state_get:
                    if (res.result.status != null)
                        if (req.guiVal.ComboBoxs != null)
                            req.guiVal.ComboBoxs[0].Text = res.result.status;
                    break;
                //
                case commandType.cmd_AutoStartUp_state_get:
                    if (res.result.operation != null)
                        if (req.guiVal.ComboBoxs != null)
                            req.guiVal.ComboBoxs[0].Text = res.result.operation;
                    break;
                case commandType.cmd_gen_operation_state_get:
                    if (res.result.operation != null)
                        if (req.guiVal.ComboBoxs != null)
                                req.guiVal.ComboBoxs[0].Text = res.result.operation;
                    break;

                case commandType.cmd_gen_operation_state_set:

                    GetOperationStateResult(req,res,res.result.taskId);
                    break;
                case commandType.cmd_gen_operation_state_set_internal:

                    GetOperationStateResult(req, res, res.result.taskId);
                    break;

                //

                case commandType.cmd_mo_loadinfo_get:
                    if (res.result.current != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.current;

                    if (res.result.average != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[1].Text = res.result.average;

                    if (res.result.uptimeSec != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[2].Text = res.result.uptimeSec;

                    break;

                case commandType.cmd_mo_meminfo_get:
                    if (res.result.memMB != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.memMB;

                    if (res.result.memfreeMB != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[1].Text = res.result.memfreeMB;

                    if (res.result.memusedMB != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[2].Text = res.result.memusedMB;

                    break;

                case commandType.cmd_mo_runtimes_get:
                 
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.mercury.ToString();

                    if (req.guiVal.TextBoxs != null)
                        req.guiVal.TextBoxs[1].Text = res.result.smps.ToString();
                   
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[2].Text = res.result.backlight.ToString();
                    
                    break;
                case commandType.cmd_mo_get_fan_speed:
                    if (res.result.speed != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.speed;
                    
                    break;

              case commandType.cmd_gen_reboot_set:
                    DisConnect_Click(null, null);
                    break;

              case commandType.cmd_cs_loop_time_get:
                    if (res.result.status != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.status;

                    if (res.result.interval != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.interval;

                    break;
              case commandType.cmd_cs_backLight_status_get:
                    if (res.result.state != null)
                        if (req.guiVal.ComboBoxs != null)
                            req.guiVal.ComboBoxs[0].Text = res.result.state;

                    break;
                case commandType.cmd_pic_red_offset_get:
                    if (res.result.value != null)
                    {
                        textBox211.Text = res.result.value;
                        Pic_Red_Offset_Slider.Value = Int32.Parse(res.result.value);
                    }
                    break;
                case commandType.cmd_pic_green_offset_get:
                    if (res.result.value != null)
                    {
                        textBox215.Text = res.result.value;
                        Pic_Green_Offset_Slider.Value = Int32.Parse(res.result.value);
                    }
                    break;
                case commandType.cmd_pic_blue_offset_get:
                    if (res.result.value != null)
                    {
                        textBox213.Text = res.result.value;
                        Pic_Blue_Offset_Slider.Value = Int32.Parse(res.result.value);
                    }
                    break;
                
                case commandType.cmd_pic_contrst_get:
                case commandType.cmd_cs_backLight_get:
                    if (res.result.value != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.value;

                    break;
                
                case commandType.cmd_mac_address_get:
                    if (res.result.macaddr != null)
                    {
                        if (res.result.macaddr.Contains("eth"))
                        {
                            string[] str = res.result.macaddr.Split('=');
                            if (req.guiVal.TextBoxs != null)
                                req.guiVal.TextBoxs[0].Text = str[1].Replace("\n", "");
                        }
                        else
                            req.guiVal.TextBoxs[0].Text = res.result.macaddr;

                        //Net_Mac_show.Text = str[1].Replace("\n", "");
                        //WOL_mac_address_txtBox.Text = Net_Mac_show.Text;
                        //WOL_IP_address_txtBox.Text = txtBox_IP.Text;
                    }
                    break;
                case commandType.cmd_mac1_address_get_internal:
                
                    if (res.result.macaddr != null)
                    {
                        string[] str = res.result.macaddr.Split('=');

                        WOL_mac1_address_txtBox.Text = str[1].Replace("\n", "");
                        
                        WOL_IP_address_txtBox.Text = txtBox_IP.Text;
                    }

                    
                    break;
                case commandType.cmd_mac2_address_get_internal:

                    if (res.result.macaddr != null)
                    {
                        string[] str = res.result.macaddr.Split('=');

                        WOL_mac2_address_txtBox.Text = str[1].Replace("\n", "");
                        WOL_IP_address_txtBox.Text = txtBox_IP.Text;
                    }

                  

                    break;
                //cmd_get_Active_input_selected

                case commandType.cmd_get_input_selected:
                    if (res.result.input != null)
                        if (req.guiVal.ComboBoxs != null)
                            req.guiVal.ComboBoxs[0].Text = res.result.input;
                        else if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.input;


                    break;
                case commandType.cmd_get_Active_input:
                   
                    if (res.result.input != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.input;
                    break;

                case commandType.cmd_img_genlock_status_get:

                    if (res.result.status != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.status;
                    break;

                    
                 
                    

                 case commandType.cmd_fpga_reg_get:
                    if (res.result.data != null)
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.data;
                    break;

                case commandType.cmd_bid_get:
                case commandType.cmd_bid_set:
                        if (req.guiVal.TextBoxs != null)
                        {
                            if (res.result.@return.ToLower() == "success")
                            {
                                if (res.result.value != null)
                                {
                                    req.guiVal.TextBoxs[0].Text = res.result.value;
                                    req.guiVal.TextBoxs[0].BackColor = Color.GreenYellow;
                                }
                                else
                                    req.guiVal.TextBoxs[0].BackColor = Color.LawnGreen;
                            }
                            else
                            {
                                req.guiVal.TextBoxs[0].Text = res.result.@return;
                                req.guiVal.TextBoxs[0].BackColor = Color.Red;
                            }

                        }
                    break;

                case commandType.cmd_fmw_update_reboot_status_get:
                    GetUpdateRebootResult(req, res, res.result.taskId);
                    break;
                case commandType.cmd_fmw_update_reboot_spi:

                    if (res.result.taskId != null)
                        GetUpdateRebootResult(req, res, res.result.taskId);
                        // = res.result.taskId;
                    break;
                case commandType.cmd_fmw_update_spi:
                    if (res.result.taskId != null)
                        GetUpdateResult(req,res,res.result.taskId);
                        // = res.result.taskId;
                    break;
                case commandType.cmd_fmw_update_status_get:
                   
                        GetUpdateResult(req, res, res.result.taskId);
                        // = res.result.taskId;
                    break;
            case commandType.cmd_module_version_get:
                    if (res.result.version != null)
                    {
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.version;
                    }
                    break;
            case commandType.cmd_mrc_spi_module_version_get:
                    if (res.result.version != null)
                    {
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.version;
                        fmw_veraion_L.Text = "FMW ver:"+req.guiVal.TextBoxs[0].Text;
                        mFmwVersion = res.result.version;
                    }
                    break;

                    
            case commandType.cmd_temprature_get:
                    
                    if (res.result.value != null)
                    {
                        if (req.guiVal.TextBoxs != null)
                            req.guiVal.TextBoxs[0].Text = res.result.value;
                    }

                    break;
            case commandType.cmd_optical_dvi_get:

                    if (res.result.status != null)
                        if (req.guiVal.ComboBoxs != null)
                            req.guiVal.ComboBoxs[0].Text = res.result.status;
                    break;
                
            }
       
        }
        public void Responce(General_responce res)
        {

            if (res == null) return;

            Monitor.Enter(request_chain);

            command_requestObj req_obj = request_chain[res.id];

            if (req_obj != null)
            {
                if (req_obj.txtBox != null)
                {
                    if (res.error != null)
                    {
                        req_obj.txtBox.Text = res.error.message;
                        req_obj.txtBox.BackColor = Color.Red;

                    }
                    else
                    {
                        req_obj.txtBox.Text = res.result.@return;
                        req_obj.txtBox.BackColor = Color.LightGreen;

                       // if (req_obj.cmdType == commandType.cmd_gen_operation_power_off_set) Monitor.Exit(request_chain);
                        try
                        {
                            handle_result(req_obj, res);
                        }
                        catch(NullReferenceException er)
                        {
                            MessageBox.Show("Null Object Returned  for rpc ID " + res.id );
                        
                        }
                       catch(Exception er)
                       {
                           MessageBox.Show(er.Message);
                       }
                    }
                }

                if (req_obj.Slider != null)
                {
                    try
                    {
                        if (res.result.@return.ToLower() != "timeout")
                            req_obj.Slider.Value = Convert.ToInt32(res.result.value);
                    }
                    catch (FormatException er)
                    {

                    }
                }
            }

            request_chain.Remove(res.id);
            Monitor.Exit(request_chain);
        }

        #endregion

        #region Gui Event Handle Mgr

        private void Kortex_gui_controls_tab_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (DisConnect.Enabled && bAutoUpdate)
            {
                TabControl Tb = (TabControl)sender;

                //TabControl Child = Tb.Controls[];

                //MessageBox.Show("KP Tab Index = " + Tb.Name +" Selected " +Tb.SelectedIndex);

                switch (Tb.SelectedIndex)
                {
                    case 1:
                        //MessageBox.Show("Picture tab");
                        pic_Get_ALL_butt_Click(null, null);

                        break;
                    case 2:
                        //MessageBox.Show("Image tab");
                        Img_GetALL_Click(null, null);
                        break;
                    case 3:
                        //MessageBox.Show("Monitoring tab");
                        Mo_Get_All_Click(null, null);
                        break;
                    case 4:
                        //MessageBox.Show("database tab");
                        DB_Get_all_Click(null, null);
                        break;
                    case 5:
                        //MessageBox.Show("Network tab");
                        NetIF_Get_All_Click(null, null);
                        break;
                    case 7:
                        //MessageBox.Show("FMW tab");
                        FMW_Get_all_Click(null, null);
                        break;
                    case 9:
                        //MessageBox.Show("ops tab");
                        ops_Get_all_Click(null, null);
                        break;


                }
            }

        }

        private void Net_GetSetNetIf_Mode_combo_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (Net_GetSetNetIf_Mode_combo.Text == "static")
            {
                textBox71.Enabled = true;
                textBox72.Enabled = true;

            }
            else
            {
                textBox71.Enabled = false;
                textBox72.Enabled = false;
            }

        }


        private void Pic_Red_gain_Slider_Scroll(object sender, EventArgs e)
        {
            txtbox_redGain_show.Text = Pic_Red_gain_Slider.Value.ToString();
        }

        private void Pic_Green_gain_Slider_Scroll(object sender, EventArgs e)
        {
            txtbox_GreenGain_show.Text = Pic_Green_gain_Slider.Value.ToString();
        }

        private void Pic_Blue_gain_Slider_Scroll(object sender, EventArgs e)
        {
            txtbox_BlueGain_show.Text = Pic_Blue_gain_Slider.Value.ToString();

        }
        private void Addedid_options_to_combo(string input_p)
        {
            

            switch(input_p)
            {
                case "dvi1":
                case "dvi2":
            this.img_DDC_timing_combo.Items.AddRange(new object[] {
            "ddc_1920_1080_25000",
            "ddc_1920_1080_25500",
            "ddc_1920_1080_29970",
            "ddc_1920_1080_30500",
            "ddc_1920_1080_50000",
            "ddc_1920_1080_50500",
            "ddc_1920_1080_59940",
            "ddc_1920_1080_60500",
            "ddc_1920_2160_25000",
            "ddc_1920_2160_25500",
            "ddc_1920_2160_29970",
            "ddc_1920_2160_30500",
            "ddc_3840_1080_25000",
            "ddc_3840_1080_25500",
            "ddc_3840_1080_29970",
            "ddc_3840_1080_30500",
            "ddc_custom"});
            img_DDC_timing_combo.Text = "ddc_1920_1080_25000";
                    break;
                case "hdmi":
                case "dp":
                case "ops":
                    this.img_DDC_timing_combo.Items.AddRange(new object[] {
            "ddc_1920_1080_25000",
            "ddc_1920_1080_25500",
            "ddc_1920_1080_29970",
            "ddc_1920_1080_30500",
            "ddc_1920_1080_50000",
            "ddc_1920_1080_50500",
            "ddc_1920_1080_59940",
            "ddc_1920_1080_60500",
            "ddc_1920_2160_25000",
            "ddc_1920_2160_25500",
            "ddc_1920_2160_29970",
            "ddc_1920_2160_30500",
            "ddc_1920_2160_50000",
            "ddc_1920_2160_50500",
            "ddc_1920_2160_59940",
            "ddc_1920_2160_60500",
            "ddc_1920_3240_25000",
            "ddc_1920_3240_25500",
            "ddc_1920_3240_29970",
            "ddc_1920_3240_30500",
            "ddc_3840_1080_25000",
            "ddc_3840_1080_25500",
            "ddc_3840_1080_29970",
            "ddc_3840_1080_30500",
            "ddc_3840_1080_50000",
            "ddc_3840_1080_50500",
            "ddc_3840_1080_59940",
            "ddc_3840_1080_60500",
            "ddc_3840_2160_25000",
            "ddc_3840_2160_25500",
            "ddc_3840_2160_29970",
            "ddc_3840_2160_30500",
                    "ddc_custom"});
             img_DDC_timing_combo.Text = "ddc_1920_1080_25000";
                    break;
                default:
                    this.img_DDC_timing_combo.Items.AddRange(new object[] {
            "ddc_1920_1080_25000",
            "ddc_1920_1080_25500",
            "ddc_1920_1080_29970",
            "ddc_1920_1080_30500",
            "ddc_1920_1080_50000",
            "ddc_1920_1080_50500",
            "ddc_1920_1080_59940",
            "ddc_1920_1080_60500",
            "ddc_1920_2160_25000",
            "ddc_1920_2160_25500",
            "ddc_1920_2160_29970",
            "ddc_1920_2160_30500",
            "ddc_3840_1080_25000",
            "ddc_3840_1080_25500",
            "ddc_3840_1080_29970",
            "ddc_3840_1080_30500",
             "ddc_custom"});
             img_DDC_timing_combo.Text = "ddc_1920_1080_25000";
                    break;

            
            }
 
        
        }

        private void Image_Set_edid_input_combo_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < img_DDC_timing_combo.Items.Count; i++)
                img_DDC_timing_combo.Items.RemoveAt(i);

            img_DDC_timing_combo.Items.Clear();


            Addedid_options_to_combo(Image_Set_edid_input_combo.Text);
        }

        private void img_DDC_timing_combo_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (img_DDC_timing_combo.Text == "ddc_custom")
            {
                Image_Set_edid_filePath_show.Enabled = true;
                Img_edid_Browse_butt.Enabled = true;
            }
            else
            {
                Image_Set_edid_filePath_show.Enabled = false;
                Img_edid_Browse_butt.Enabled = false;
            }


        }

        private void Hw_mem_test_Pass_box_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                Hw_memory_test_enable_Click(null, null);
            }

        }


       

        private void Gen_fmw_update_type_combo_SelectedIndexChanged(object sender, EventArgs e)
        {
           /* if (UserType == "expert")
            {
                if (Gen_fmw_update_type_combo.Text == "MrcPs171")
                    ps171_bankRadio_box.Enabled = true;
                else
                    ps171_bankRadio_box.Enabled = false;
            }
            * */


        }


        #region string to Byte Array
        public static byte C2b(char c)
        {
            if ((int)c < 256) return (byte)c;
            throw new Exception("character overflows a byte");
        }
        public static byte[] S2b(string value)
        {
            byte[] buffer = new byte[value.Length];
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = C2b(value[i]);
            }

            return buffer;
        }
        #endregion


        private bool CheckRedundantIp(string Ip,string []IpArr)
        {
            foreach (string Ipadr in IpArr)
            {
                if (Ipadr == Ip) return true;
            
            }

            return false;
        }
        private void txtBox_IP_Leave(object sender, EventArgs e)
        {
            FileStream FStream = null;
            //localDir

            try
            {
                FileInfo MyFile = new FileInfo(localDir+"\\IpAddress.txt");

                if (MyFile.Exists)
                {
                    

                    FStream = File.OpenRead(localDir + "\\IpAddress.txt");
                    int count = 0;
                    byte[] Buff = new Byte[FStream.Length];
                    count = FStream.Read(Buff, 0, (Int32)FStream.Length);
                    FStream.Close();
                    string AllIps = System.Text.ASCIIEncoding.ASCII.GetString(Buff);
                    string[] AdIp = AllIps.Split("|".ToCharArray());
                    MyFile.Delete();
                    Thread.Sleep(200);
                    

                    FStream = File.OpenWrite(localDir + "\\IpAddress.txt");
                    FStream.Seek(0, SeekOrigin.Begin);

                    
                        FStream.Write(S2b(txtBox_IP.Text), 0, txtBox_IP.Text.Length);
                        FStream.Write(S2b("|"), 0, 1);
                    
                    for (int i = 0; i < AdIp.Length -1; i++) 
                    {
                        if(AdIp[i] != txtBox_IP.Text)    
                        {
                         FStream.Write(S2b(AdIp[i]), 0, AdIp[i].Length);
                         FStream.Write(S2b("|"), 0, 1);
                        }
                        
                    }
                    FStream.Close();
                }
                else
                {
                    FStream = File.OpenWrite(localDir + "\\IpAddress.txt");
                    FStream.Seek(0, SeekOrigin.Begin);
                    FStream.Write(S2b(txtBox_IP.Text), 0, txtBox_IP.Text.Length);
                    //FStream.Write(S2b("|"), 0, 1);
                    FStream.Close();
 
                }


            }
            catch (FileLoadException)
            {
                throw new ArgumentException("Exception Occured During the JSON File Open in Write mode ");

            }
            catch (UnauthorizedAccessException er)
            {

                throw new ArgumentException("Picture.cs UnauthorizedAccessException GenPOSTSetSence6TriggerJSON " + er.Message);
            }



        }

        private void Img_optical_dvi_get_radio_CheckedChanged(object sender, EventArgs e)
        {
            Image_optical_status_combo.Visible = false;


        }

       
        private void Pic_Contrast_Slider_Scroll(object sender, EventArgs e)
        {
            txtboxControst_show.Text = Pic_Contrast_Slider.Value.ToString();
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            txtboxBacklight_show.Text = Pic_Backlight_Slider.Value.ToString();
        }

        private void Pic_Brightness_Slider_Scroll(object sender, EventArgs e)
        {

            txtbox_Brightness_show.Text = Pic_Brightness_Slider.Value.ToString();

        }


        private void KortexGuiMain_Leave(object sender, EventArgs e)
        {
            //DisConnect_Click(null, null);

        }

        private void KortexGuiMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            //if (DisConnect.Enabled == true)
                DisConnect_Click(null, null);
                notifyIcon1.Visible = false;
                notifyIcon1.Dispose();

        }



        #endregion

        #region General Tab Commands


        private void Genral_reboot_Click(object sender, EventArgs e)
        {
            int id;
            textBox28888.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_gen_reboot_set, textBox28888);
            Monitor.Enter(request_chain);
            id = AllCommands.SetReboot();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        }



        private void Gen_Getautostartup_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox87.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Gen_AutoStartup_combo);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_AutoStartUp_state_get, textBox87, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_device_startup");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Gen_Setautostartup_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox87.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_AutoStartUp_state_set, textBox87);
            Monitor.Enter(request_chain);
            id = AllCommands.SetAutoStartUpState(Gen_AutoStartup_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void Gen_GetSetautostartup_ClearAll_Click(object sender, EventArgs e)
        {

        }
        
        private void Gen_op_state_get_butt_Click(object sender, EventArgs e)
        {
            int id;
            Set_Op_state_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Gen_Op_state_combo);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_gen_operation_state_get, Set_Op_state_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_device_operation");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Gen_op_state_ClearALl_butt_Click(object sender, EventArgs e)
        {
            

        }

        private double CheckFmwVersion()
        {
            string value = Regex.Replace(mFmwVersion, "[A-Za-z ]", "");
            string[] parts = value.Split('.');
            double version = Convert.ToDouble(parts[0] + "." + parts[1]);
            return version;
        }

        private void Gen_op_state_Set_butt_Click(object sender, EventArgs e)
        {
            int id;


            if (CheckFmwVersion() >= 0.54)
            {

                Set_Op_state_show.BackColor = Color.HotPink;
                command_requestObj obj = new command_requestObj(Common.commandType.cmd_gen_operation_state_set, Set_Op_state_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetOperationState(Gen_Op_state_combo.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
            }
            else
            {
                if (Gen_Op_state_combo.Text != "reboot")
                {
                    MessageBox.Show("Only Reboot is posible with this version ");
                    return;
                }
                Set_Op_state_show.BackColor = Color.HotPink;
                command_requestObj obj = new command_requestObj(Common.commandType.cmd_gen_reboot_set, Set_Op_state_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetReboot();
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                
            
            }
            
            /* string state = Gen_Op_state_combo.Text;
            if (state == "idle") state = "off";
            else if (state == "off") state = "poweroff";
            

            command_requestObj obj;

            int id;
            Set_Op_state_show.BackColor = Color.HotPink;
            if (state == "poweroff")
                obj = new command_requestObj(Common.commandType.cmd_gen_operation_power_off_set, Set_Op_state_show);
            else
             obj = new command_requestObj(Common.commandType.cmd_gen_operation_state_set, Set_Op_state_show);

            Monitor.Enter(request_chain);
            if (state == "poweroff")
                id = AllCommands.SetPowerOff();
            else
              id = AllCommands.SetOperationState(state);
            
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            * */
        }

        private void Gen_op_state_SetClearALl_butt_Click(object sender, EventArgs e)
        {
            Set_Op_state_show.Clear();
            Set_Op_state_show.BackColor = Color.White;
        }

        #endregion



        #region Picture tab Commands

        private void pic_Red_Offset_Apply_butt_Click(object sender, EventArgs e)
        {
           

        }

        private void pic_Red_Offset_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox41.BackColor = Color.HotPink;
            GuiBoxArray gui = null;// new GuiBoxArray();
            //gui.Add(txtbox_redGain_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_red_offset_get, textBox41, Pic_Red_Offset_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetRedOffset();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_Green_Offset_Apply_butt_Click(object sender, EventArgs e)
        {

        }

        private void pic_Green_Offset_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox214.BackColor = Color.HotPink;
            GuiBoxArray gui = null;// new GuiBoxArray();
            //gui.Add(txtbox_redGain_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_green_offset_get, textBox214, Pic_Green_Offset_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGreenOffset();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_Blue_Offset_Apply_butt_Click(object sender, EventArgs e)
        {

        }

        private void pic_Blue_Offset_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox212.BackColor = Color.HotPink;
            GuiBoxArray gui = null;// new GuiBoxArray();
            //gui.Add(txtbox_redGain_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_blue_offset_get, textBox212, Pic_Blue_Offset_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBlueOffset();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }


        private void Pic_BackLightBostSet_but_Click(object sender, EventArgs e)
        {
            int id;
            PIc_BsckLightBoost_Result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_boostLight_set, PIc_BsckLightBoost_Result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetBackLightBoost(pic_backLIghtBoost_conbo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void Pic_BackLightBostClearAll_but_Click(object sender, EventArgs e)
        {

        }
        private void pic_Reg_gain_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox49.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(txtbox_redGain_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_contrst_get, textBox49, Pic_Red_gain_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetRedGain();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_Red_gain_Apply_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox49.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, textBox49);
            Monitor.Enter(request_chain);
            id = AllCommands.SetRedGain(Convert.ToInt32(txtbox_redGain_show.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_Green_gain_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox47.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(txtbox_GreenGain_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_contrst_get, textBox47, Pic_Green_gain_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGreenGain();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_Green_gain_Apply_butt_Click(object sender, EventArgs e)
        {

            int id;
            textBox47.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, textBox47);
            Monitor.Enter(request_chain);
            id = AllCommands.SetGreenGain(Convert.ToInt32(txtbox_GreenGain_show.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_Blue_gain_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox34.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(txtbox_BlueGain_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_contrst_get, textBox34, Pic_Blue_gain_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBlueGain();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_Blue_gain_Apply_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox34.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, textBox34);
            Monitor.Enter(request_chain);
            id = AllCommands.SetBlueGain(Convert.ToInt32(txtbox_BlueGain_show.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }


        private void pic_Contrast_Apply_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox48.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_contrst_set, textBox48);
            Monitor.Enter(request_chain);
            id = AllCommands.SetContrast(Convert.ToInt32(txtboxControst_show.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void pic_Get_ALL_butt_Click(object sender, EventArgs e)
        {
            pic_Contrast_Get_butt_Click(null, null);
            pic_BackLlight_Get_butt_Click(null, null);
            pic_Brightness_Get_butt_Click(null, null);
            pic_Reg_gain_Get_butt_Click(null, null);
            pic_Green_gain_Get_butt_Click(null, null);
            pic_Blue_gain_Get_butt_Click(null, null);
            pic_Red_Offset_Get_butt_Click(null, null);
            pic_Green_Offset_Get_butt_Click(null, null);
            pic_Blue_Offset_Get_butt_Click(null, null);
        }


        private void pic_Apply_ALL_butt_Click(object sender, EventArgs e)
        {
            pic_Contrast_Apply_butt_Click(null, null);
            pic_BackLight_Apply_butt_Click(null, null);
            pic_Brightness_Apply_butt_Click(null, null);
            pic_Red_gain_Apply_butt_Click(null, null);
            pic_Green_gain_Apply_butt_Click(null, null);
            pic_Blue_gain_Apply_butt_Click(null, null);


        }

        private void pic_Contrast_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox48.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(txtboxControst_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_contrst_get, textBox48, Pic_Contrast_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetContrast();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void pic_BackLight_Apply_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox46.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, textBox46);
            Monitor.Enter(request_chain);
            id = AllCommands.SetBackLight(Convert.ToInt32(txtboxBacklight_show.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_BackLlight_Get_butt_Click(object sender, EventArgs e)
        {

            int id;
            textBox46.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(txtboxBacklight_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_contrst_get, textBox46, Pic_Backlight_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBackLight();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }


        private void pic_Brightness_Apply_butt_Click(object sender, EventArgs e)
        {

            int id;
            textBox45.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, textBox45);
            Monitor.Enter(request_chain);
            id = AllCommands.SetBrightness(Convert.ToInt32(txtbox_Brightness_show.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void pic_Brightness_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox45.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(txtbox_Brightness_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_pic_contrst_get, textBox45, Pic_Brightness_Slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBrightness();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

      
        
        #endregion


        #region Passwords
        private static string GetAuthExpert()
        {
            char[] Data = new char[6];

            Data[0] = (char)0x67;
            Data[1] = (char)0x6C;
            Data[2] = (char)0x61;
            Data[3] = (char)0x64;
            Data[4] = (char)0x39;
            Data[5] = (char)0x39;
            //Data[6] = (char)'\0';
            string s = new string(Data);


            return s;
        }

        private static string GetkpAuth()
        {
            char[] Data = new char[9];

            Data[0] = (char)0x6B;
            Data[1] = (char)0x70;
            Data[2] = (char)0x6c;
            Data[3] = (char)0x6f;
            Data[4] = (char)0x76;
            Data[5] = (char)0x65;
            
            Data[6] = (char)0x79;
            Data[7] = (char)0x6f;
            Data[8] = (char)0x75;
            //Data[6] = (char)'\0';
            string s = new string(Data);


            return s;
        }

        private  string  GetDyki()
        {
            
            char[] Data = new char[11];

            Data[0] = (char)0x42;
            Data[1] = (char)0x61;
            Data[2] = (char)0x72;
            Data[3] = (char)0x63;
            Data[4] = (char)0x6F;
            Data[5] = (char)0x23;
            Data[6] = (char)0x31;
            Data[7] = (char)0x32;
            Data[8] = (char)0x38;
            Data[9] = (char)0x2F;
            Data[10] = (char)0x35;
            
            return new string (Data);
        }

        #endregion

        #region General

        private void Gen_Fmw_updae_Set_butt_Click(object sender, EventArgs e)
        {
            DialogResult ret = MessageBox.Show("Current version of OVD/KVD firmware does not support failsafe upgrade mechanism,Please ensure that power to panel is not interrupted during this 3 minutes of upgrade time.Do you want to continue?", "WARNING!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (ret != System.Windows.Forms.DialogResult.Yes) return;
            
            
            int id;
            Gen_Fmw_updare_result_show.BackColor = Color.HotPink;
            string BankInfo = string.Empty;
            string dyKI = GetDyki();
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_fmw_update_spi, Gen_Fmw_updare_result_show);

            if (CheckFmwVersion() >= 0.32)
            {
                if (Gen_Fmw_updare_filepath_show.Text != "")
                    KpScpSshclt.kp_scp(txtBox_IP.Text, Gen_Fmw_updare_filepath_show.Text, "/tmp/fmwUpdate.bin", dyKI);
            }else
                if (Gen_Fmw_updare_filepath_show.Text != "")
                    KpScpSshclt.kp_scp_root(txtBox_IP.Text, Gen_Fmw_updare_filepath_show.Text, "/tmp/fmwUpdate.bin", dyKI);


           /* if (Gen_fmw_update_type_combo.Text == "MrcPs171")
            {
                if (Gen_ps171_Bank2_radio.Checked)
                {
                    string file = localDir + "\\bank2_cmd_1";
                    KpScpSshclt.kp_scp(txtBox_IP.Text, file, "/tmp/bank2_cmd_1", dyKI);
                    file = localDir + "\\bank2_cmd_2";
                    KpScpSshclt.kp_scp(txtBox_IP.Text, file, "/tmp/bank2_cmd_2", dyKI);
                    BankInfo = "bank2";
                }
                else if (Gen_ps171_Bank3_radio.Checked)
                {
                    string file = localDir + "\\bank3_cmd_1";
                    KpScpSshclt.kp_scp(txtBox_IP.Text, file, "/tmp/bank3_cmd_1", dyKI);
                    file = localDir + "\\bank3_cmd_2";
                    KpScpSshclt.kp_scp(txtBox_IP.Text, file, "/tmp/bank3_cmd_2", dyKI);
                    BankInfo = "bank3";
                
                }
                
            }
            else if (Gen_fmw_update_type_combo.Text == "MrcMstar")
            {
                BankInfo = UserType;
            }
            * */
            
                
            Monitor.Enter(request_chain);
            id = AllCommands.updateFirmware(Gen_fmw_update_type_combo.Text, "/tmp/fmwUpdate.bin", BankInfo);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
           
        }

        private void Gen_Fmw_updae_Clear_butt_Click(object sender, EventArgs e)
        {
            Gen_Fmw_updare_result_show.Clear();
            Gen_Fmw_updare_result_show.BackColor = Color.White;
        }

        private void Gen_Fmw_updae_Brwse_butt_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            Gen_Fmw_updare_filepath_show.Text = openFileDialog1.FileName;
        }

       
        

        private void Identify_proj_Click(object sender, EventArgs e)
        {
            int id;
            //Img_ShowMstar_video_result.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, textBox28888);
            Monitor.Enter(request_chain);
            id = AllCommands.SetGeneric_SysMgr("set_device_identify");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }


        private void ConnectCube()
        {
            try
            {
                //AllCommands.ConnectTosdVideoService(txtBox_IP.Text, 42510);
                AllCommands.ConnectTosdPanelService(txtBox_IP.Text, 42511);
               //AllCommands.ConnectTosdFpgaService(txtBox_IP.Text, 42512);
                //AllCommands.ConnectTosdSysMgrService(txtBox_IP.Text, 42513);//Now this will be at Original Connect_Click
                AllCommands.ConnectTosdInputService(txtBox_IP.Text, 42514);
                AllCommands.ConnectTosdColorService(txtBox_IP.Text, 42516);
            }
            catch (Exception er)
            {
                 MessageBox.Show(er.Message + " Now tool is going to disconnect completely. ");
               // MessageBox.Show("Old Firmware found!! connecting partially to fecilitate upgrade to latest version","WARNING!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DisConnect_Click(null, null);

                //ConnectAny();

                return;

            }
            /*try
             {
               AllCommands.ConnectTosdFpgaService(txtBox_IP.Text, 42512);
             }
             catch (Exception er)
             {
                 MessageBox.Show(er.Message);
             }
                
             try
             {
                    AllCommands.ConnectTosdSysMgrService(txtBox_IP.Text, 42513);
             }
             catch (Exception er)
             {
                 MessageBox.Show(er.Message);
             }

             try
             {
             AllCommands.ConnectTosdInputService(txtBox_IP.Text, 42514);
             }
             catch (Exception er)
             {
                 MessageBox.Show(er.Message);
             }
             */
            //fmw_version_Get_butt_Click(null, null);
            Net_GetMac_intenal("eth0");
            Net_GetMac_intenal("eth1");
            Ops_Control_Panel_refresh_Click(null, null);

            Connect.Enabled = false;
            DisConnect.Enabled = true;
            run = true;

            /*
            if (Color_sensorT ==null)
            Color_sensorT = new Thread(ColorSensor_autoupdate_thread);
            Color_sensorT.Start();
           */

        }

        public void ConnectAny()
        {
            int id;
            Cube_command_reqObj obj = null;

            if (txtBox_IP.Text != string.Empty && txtBox_IP.Text.Contains(".") && !iSconnect)
            {
                try
                {
                    AllCommands.ConnectTosdPanelService(txtBox_IP.Text, 42511);

                }
                catch (Exception er)
                {
                    //IsConnected = false;
                    MessageBox.Show("Error While Connect at Cube    Message= " + er.Message);
                }

                /*try
                {
                   
                    AllCommands.ConnectTosdFpgaService(mIp, 42512);
                    
                }
                catch (Exception er)
                {
                    //IsConnected = false;
                    MessageBox.Show("Error While Connect at Cube " + pos_Col + "," + pos_Row + "  Message= " + er.Message);
                }
                 * */

                try
                {
                    AllCommands.ConnectTosdSysMgrService(txtBox_IP.Text, 42513);

                }
                catch (Exception er)
                {
                    // IsConnected = false;
                    MessageBox.Show("Error While Connect at Cube    Message= " + er.Message);
                }

                try
                {
                    AllCommands.ConnectTosdInputService(txtBox_IP.Text, 42514);

                }
                catch (Exception er)
                {
                    // IsConnected = false;
                    MessageBox.Show("Error While Connect at Cube    Message= " + er.Message);
                }

                try
                {
                    AllCommands.ConnectTosdColorService(txtBox_IP.Text, 42516);
                }
                catch (Exception er)
                {
                    //IsConnected = false;
                    //MessageBox.Show("Error While Connect at Cube    Message= " + er.Message);
                }

                Connect.Enabled = false;
                DisConnect.Enabled = true;
                fmw_version_Get_butt_Click(null, null);

            }


        }


        private void Connect_sdsms()
        {
            try
            {
                AllCommands.ConnectTosdSysMgrService(txtBox_IP.Text, 42513);
                GetFmw_version_atConnect();
                
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message + " Now tool is going to disconnect completely. ");
                //MessageBox.Show("Old Firmware found!! connecting partially to fecilitate upgrade to latest version", "WARNING!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DisConnect_Click(null, null);
                return;
            }
 
        
        }


        private void GetFmw_version_atConnect()
        {
            int id;
            fmw_version_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mrc_spi_module_version_at_connect_get, fmw_version_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetModuleVersion("MrcSpiProj");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        
        
        
        }
        private void Connect_Click(object sender, EventArgs e)
        {
            /*
            if (COntrol_CheckAllService_CheckBox.Checked)
                ConnectAny();    
            else
                ConnectCube();    
            */
            mFmwVersion = string.Empty;

            Connect_sdsms();
            


        }





        private void DisConnect_Click(object sender, EventArgs e)
        {

           
            run = false;
            Connect.Enabled = true;
            DisConnect.Enabled = false;
            if (Color_sensorT != null)
                Color_sensorT.Abort();
            Color_sensorT = null;
            request_chain.Clear();
            
              AllCommands.DisConnectFromServr();
            
        }
        #endregion


        #region Image tab Commands

     

        private void Img_Optical_cable_Set()
        {
            int id;
            Imag_Optical_dvi_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_optical_dvi_set, Imag_Optical_dvi_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetDviOptical(Imag_Optical_dvi_combo.Text, Image_optical_status_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_Get_VideoBypass_but_Click(object sender, EventArgs e)
        {
            int id;
            Imag_GetSetVideoByPass_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Img_VideoByPass_combo);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_video_byPass_get, Imag_GetSetVideoByPass_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetVideoByPass(Img_VideoBypass_input_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_Set_VideoBypass_but_Click(object sender, EventArgs e)
        {
            int id;
            Imag_GetSetVideoByPass_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_video_byPass_set, Imag_GetSetVideoByPass_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetVideoByPass(Img_VideoBypass_input_combo.Text, Img_VideoByPass_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
           

        }

        private void Img_GetSet_VideoBypass_ClearAllbut_Click(object sender, EventArgs e)
        {
            Imag_GetSetVideoByPass_result_show.Clear();
            Imag_GetSetVideoByPass_result_show.BackColor = Color.White;

        }

        private void Imag_Optical_dvi_get_butt_Click_1(object sender, EventArgs e)
        {
            int id;
            Imag_Optical_dvi_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Image_optical_status_combo);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_optical_dvi_get, Imag_Optical_dvi_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetDviOptical(Imag_Optical_dvi_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
           // fmw_version_result_show.Text = "Result Sent";

        }

        private void Imag_Optical_dvi_Set_butt_Click(object sender, EventArgs e)
        {
            int id;
            Imag_Optical_dvi_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Image_optical_status_combo);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_optical_dvi_set, Imag_Optical_dvi_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.SetDviOptical(Imag_Optical_dvi_combo.Text, Image_optical_status_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            fmw_version_result_show.Text = "Result Sent";

        }
        private void Imag_Optical_dvi_Clearall_butt_Click(object sender, EventArgs e)
        {
            Imag_Optical_dvi_result_show.Clear();
            Imag_Optical_dvi_result_show.BackColor = Color.White;
            
        }




        private void Img_WallConfigGet_butt_Click(object sender, EventArgs e)
        {
            int id;
            img_wallConfig_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Img_WallConfig_state_combo);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wallConfig_get, img_wallConfig_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetWallConfig();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }


        private void img_Background_get_Click(object sender, EventArgs e)
        {
            int id;
            Img_background_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox51, textBox52, textBox53);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_background_get, Img_background_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBackgroundColor();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void img_Backgouond_color_picker_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();

            textBox51.Text = colorDialog1.Color.R.ToString();
            textBox52.Text = colorDialog1.Color.G.ToString();
            textBox53.Text = colorDialog1.Color.B.ToString();

            Img_Color_picker_show_panel.BackColor = colorDialog1.Color;

        }

        private void img_Background_set_Click(object sender, EventArgs e)
        {

            int id;
            int r = Convert.ToInt32(textBox51.Text);
            int g = Convert.ToInt32(textBox52.Text);
            int b = Convert.ToInt32(textBox53.Text);

            Img_background_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wallConfig_set, Img_background_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetBackgroundColor(img_background_combo.Text,r,g,b);
            SetColorPickerPanelBgCOlor(img_background_combo.Text, r, g, b);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void img_Background_ClearALL_Click(object sender, EventArgs e)
        {
            Img_background_result_show.Clear();
            Img_background_result_show.BackColor = Color.White;
            textBox51.Clear();
            textBox52.Clear();
            textBox53.Clear();


        }

        private void Img_WallConfigSet_butt_Click(object sender, EventArgs e)
        {

            int id;
            img_wallConfig_Result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wallConfig_set, img_wallConfig_Result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetWallConfig(Img_WallConfig_state_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_WallConfig_Clearall_butt_Click(object sender, EventArgs e)
        {
            img_wallConfig_Result_show.Clear();
            img_wallConfig_Result_show.BackColor = Color.White;
        }


        private void Img_Get_Pattern_butt_Click(object sender, EventArgs e)
        {
            int id;
            Img_getSet_pattern_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(img_PatternType_combo);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_pattern_type_get, Img_getSet_pattern_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_input("get_pattern");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_Set_Pattern_butt_Click(object sender, EventArgs e)
        {
            int id;
            Img_getSet_pattern_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_pattern_type_set, Img_getSet_pattern_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetPattern(img_PatternType_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_Get_Pattern_ClearALlbutt_Click(object sender, EventArgs e)
        {
            Img_getSet_pattern_result_show.Clear();
            Img_getSet_pattern_result_show.BackColor = Color.White;
        }

        private void Img_GetInputTiming_but_Click(object sender, EventArgs e)
        {
            int id;
            Img_getInputTiming_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox66,textBox68,textBox70,textBox69);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_input_timing_get, Img_getInputTiming_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetInputTiming(img_channeling_timeing_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        }

        private void Img_GetInputTiming_ClearAll_but_Click(object sender, EventArgs e)
        {
            Img_getInputTiming_result_show.Clear();
            Img_getInputTiming_result_show.BackColor = Color.White;
            textBox66.Clear();
            textBox68.Clear();
            textBox70.Clear();
            textBox69.Clear();


        }

        private void Img_Wall_FullScreanGet_butt_Click(object sender, EventArgs e)
        {
            int id;
            img_wallFullScrean_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Img_WallFullScrean_state_combo);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wallConfig_state_get, img_wallFullScrean_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetWallFullScrean();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_Wall_FullScreanSet_butt_Click(object sender, EventArgs e)
        {
            

            int id;
            img_wallFullScrean_Result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wallConfig_state_set, img_wallFullScrean_Result_show);
            Monitor.Enter(request_chain);
            if (img_WallGeo_Enable_ON_radio.Checked)
            id = AllCommands.SetWallFullScrean("on");
            else
                id = AllCommands.SetWallFullScrean("off");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_Wall_FullScrean_ClearAll_butt_Click(object sender, EventArgs e)
        {

            img_wallFullScrean_Result_show.Clear();
            img_wallFullScrean_Result_show.BackColor = Color.White;

        }


        private void Img_Wall_GetGeoMetry_butt_Click(object sender, EventArgs e)
        {
            int id;
            Img_Wall_geo_Result.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(WallGeo_X, WallGeo_Y, WallGeo_X_max, WallGeo_Y_max);
           
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wallGeometry_get, Img_Wall_geo_Result, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetWallGeometry(img_WallGeoMetry_input.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

           
             gui = new GuiBoxArray();
            gui.Add(Img_WallFullScrean_state_combo);

             obj = new command_requestObj(Common.commandType.cmd_img_wallConfig_state_get, img_wallFullScrean_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetWallFullScrean();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

           

        }

        private void Img_Wall_SetGeoMetry_butt_Click(object sender, EventArgs e)
        {
            int id;
            int x=0,y=0,xmax=1,ymax=1;
            Img_Wall_geo_Result.BackColor = Color.HotPink;

            
            x = Convert.ToInt32(WallGeo_X.Text);
            y = Convert.ToInt32(WallGeo_Y.Text);
            xmax = Convert.ToInt32(WallGeo_X_max.Text);
            ymax = Convert.ToInt32(WallGeo_Y_max.Text);
            
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wallGeometry_set, Img_Wall_geo_Result);
            Monitor.Enter(request_chain);
            id = AllCommands.SetWallGeometry(x, y, xmax, ymax, img_WallGeoMetry_input.Text, img_WallGeoMetry_Mode.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

           
             obj = new command_requestObj(Common.commandType.cmd_img_wallConfig_state_set, img_wallFullScrean_Result_show);
            Monitor.Enter(request_chain);
            if (img_WallGeo_Enable_ON_radio.Checked)
                id = AllCommands.SetWallFullScrean("on");
            else
                id = AllCommands.SetWallFullScrean("off");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void Img_Wall_ClearALLGeoMetry_butt_Click(object sender, EventArgs e)
        {
            WallGeo_X.Clear();
            WallGeo_Y.Clear();
            WallGeo_X_max.Clear();
            WallGeo_Y_max.Clear();
            //img_WallGeoMetry_input.Text = "";
            //img_WallGeoMetry_Mode.Text = "";
                

        }

       


        private void SetEdid(string Filepath)
        {
            int id;
            Image_Set_edid_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_edid_set, Image_Set_edid_result_show);

            Monitor.Enter(request_chain);

            if (Filepath == "custom")
            {
                KpScpSshclt.kp_scp(txtBox_IP.Text, Image_Set_edid_filePath_show.Text, "/tmp/cutomEdit.bin", GetDyki());
                id = AllCommands.Setedid(Image_Set_edid_input_combo.Text, "custom", "/tmp/cutomEdit.bin");
            }
            else
                id = AllCommands.Setedid(Image_Set_edid_input_combo.Text, img_DDC_timing_combo.Text, Filepath);
             
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        
        }

        private void VerifyEdit(string Filepath)
        {
            int id;
            Image_Set_edid_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_edid_set, Image_Set_edid_result_show);
            Monitor.Enter(request_chain);
            if (Filepath == "custom")
            {
                KpScpSshclt.kp_scp(txtBox_IP.Text, Image_Set_edid_filePath_show.Text, "/tmp/cutomEdit.bin", GetDyki());
                id = AllCommands.Verifyedid(Image_Set_edid_input_combo.Text, "/tmp/cutomEdit.bin");
            }
            else
                id = AllCommands.Verifyedid(Image_Set_edid_input_combo.Text, Filepath);
            
            request_chain[id] = obj;
            Monitor.Exit(request_chain);



        }

        private void Img_edid_Browse_butt_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            Image_Set_edid_filePath_show.Text = openFileDialog1.FileName;
        }
       

        private void Image_Set_edid_butt_set_Click(object sender, EventArgs e)
        {
            string filePath = string.Empty;
            string Intput = Image_Set_edid_input_combo.Text + "/";

            if (Intput == "ops/") Intput = "hdmi/";
            if (Intput == "dvi1/" || Intput == "dvi2/") Intput = "dvi/";

            filePath = "/opt/fmw/edid_files/OVD_KVD_XX21/" + Intput + img_DDC_timing_combo.Text + ".bin";

            if (Image_Set_edid_Set_Radio_butt.Checked == true)
            {
                if (img_DDC_timing_combo.Text == "ddc_custom")
                SetEdid("custom");
                else
                    SetEdid(filePath);

            }

            if (Image_Set_edid_Verify_Radio_butt.Checked == true)
            {
                if (img_DDC_timing_combo.Text == "ddc_custom")
                    VerifyEdit("custom");
                else
                    VerifyEdit(filePath);

            }


            /*string filePath = string.Empty; 
            string Intput = Image_Set_edid_input_combo.Text + "/";

            if(Intput == "ops/") Intput = "hdmi/";
            if (Intput == "dvi1/" || Intput == "dvi2/") Intput = "dvi/";

            filePath = "/opt/fmw/edid_files/OVD_KVD_XX21/" + Intput + img_DDC_timing_combo.Text + ".bin";

            if (Image_Set_edid_Set_Radio_butt.Checked == true)
            {
                if (img_DDC_timing_combo.Text == "ddc_custom")
                SetEdid(string.Empty);
                else
                    SetEdid(filePath);

            }

            if (Image_Set_edid_Verify_Radio_butt.Checked == true)
            {
                if (img_DDC_timing_combo.Text == "ddc_custom")
                    VerifyEdit(string.Empty);
                else
                    VerifyEdit(filePath);

            }
             * */



        }

        private void Image_Set_edid_butt_Clearall_Click(object sender, EventArgs e)
        {
            Image_Set_edid_result_show.Clear();
            Image_Set_edid_result_show.BackColor = Color.White;

           // sshScp kp = new sshScp();
           // sshScp.Scp("to", "d:\\temp\\CNB_GKP.pdf", "/tmp/kp.pdf");
           // KpScpSshclt.kp_scp("10.64.16.93", @"d:\temp\kp.txt", "/tmp/Againkp.txt");


        }

        private void Img_GetSourceSelected_butt_Click(object sender, EventArgs e)
        {

            int id;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, textBox28888);
            Monitor.Enter(request_chain);
            id = AllCommands.GetKortexActiveSource();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }
       

        private void Img_GetALL_Click(object sender, EventArgs e)
        {
            Img_GetMercurySourceSelected_butt_Click(null, null);
            Imag_Optical_dvi_get_butt_Click_1(null, null);
            Img_GetInputTiming_but_Click(null, null);
            Img_get_genLockStatus_get_butt_Click(null, null);
            Img_Wall_GetGeoMetry_butt_Click(null, null);
            img_Background_get_Click(null, null);
            //Img_Wall_FullScreanGet_butt_Click(null, null);
            img_getActive_source_get_butt_Click(null, null);
            Img_Get_erros_but_Click(null, null);
            Img_Get_VideoBypass_but_Click(null, null);
            Img_Get_Pattern_butt_Click(null, null);
        }


        private void img_getActive_source_get_butt_Click(object sender, EventArgs e)
        {
            int id;
            Img_activeSopurce_Result_Show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Img_activeSopurce_get_Show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_get_Active_input, Img_activeSopurce_Result_Show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetMercuryActiveSource();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void img_getActive_source_Clearall_Click(object sender, EventArgs e)
        {

        }

        private void Img_SetMstar_video_but_Click(object sender, EventArgs e)
        {
            int id;
            Img_ShowMstar_video_result.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_mstar_video_set, Img_ShowMstar_video_result);
            Monitor.Enter(request_chain);
            id = AllCommands.SetMstarSourceShow();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        }

        private void Img_SetMstar_video_ClearAllbut_Click(object sender, EventArgs e)
        {
            Img_ShowMstar_video_result.Clear();
            Img_ShowMstar_video_result.BackColor = Color.White;
        }

        private void Img_Get_erros_but_Click(object sender, EventArgs e)
        {
            int id;
            img_Errors_get_results_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox65, textBox73);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_errors_get, img_Errors_get_results_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_input("get_videoBypass_wallCfg_error");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_Get_erros_ClearALL_but_Click(object sender, EventArgs e)
        {
            img_Errors_get_results_show.Clear();
            img_Errors_get_results_show.BackColor = Color.White;
            textBox65.Clear();
            textBox73.Clear();
        }

        private void Img_set_genLockStatus_get_butt_Click(object sender, EventArgs e)
        {
            //Ssh_command obj = null; ;

            string result = KpScpSshclt.kp_runCmd(txtBox_IP.Text, "fr 318", GetDyki());
            string[] Data = result.Split('-');
            Data[2] = Data[2].Trim();
            char[] Val = Data[2].ToCharArray();
            string command = "fw 318 ";

            switch (img_GenLock_combo.Text)
            {
                    

                case "inactive":
                   // obj = new Ssh_command("fw 318 0000", Img_set_genLockStatus_get_butt);
                   Val[3] = '0';
                   //string s = new string(c);
                   command += new string(Val);
                   result = KpScpSshclt.kp_runCmd(txtBox_IP.Text, command, GetDyki());
                    break;
                case "single":
                     Val[3] = '4';
                     command += new string(Val);
                   result = KpScpSshclt.kp_runCmd(txtBox_IP.Text, command, GetDyki());
                    break;
                case "double":
                    Val[3] = '6';
                    command += new string(Val);
                   result = KpScpSshclt.kp_runCmd(txtBox_IP.Text, command, GetDyki());
                    break;
                case "bypass":
                   Val[3] = 'D';
                   command += new string(Val);
                   result = KpScpSshclt.kp_runCmd(txtBox_IP.Text, command, GetDyki());
                    break;
                default:
                    Val[3] = '0';
                    command += new string(Val);
                   result = KpScpSshclt.kp_runCmd(txtBox_IP.Text, command, GetDyki());
                   break;


            }


            

            // RunSSH_cmd 
            //KpScpSshclt.kp_runCmd(


        }

        private void Img_Set_genLockStatus_ClearAll_butt_Click(object sender, EventArgs e)
        {

        }


        private void Img_get_genLockStatus_get_butt_Click(object sender, EventArgs e)
        {
            int id;
            Img_get_genLockStatus_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Img_get_genLockStatus_status);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_genlock_status_get, Img_get_genLockStatus_result_show, gui);
            
            Monitor.Enter(request_chain);
            id = AllCommands.GetGetLockStatus();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Img_get_genLockStatus_ClearAll_butt_Click(object sender, EventArgs e)
        {
            Img_get_genLockStatus_result_show.Clear();
            Img_get_genLockStatus_result_show.BackColor = Color.White;
            Img_get_genLockStatus_status.Clear();
        }
        

        private void Img_GetMercurySourceSelected_butt_Click(object sender, EventArgs e)
        {

            int id;
            Image_MercurySetSource_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Image_MercurySourceList_combo);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_get_input_selected, Image_MercurySetSource_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetMercurySelectedSource();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }
        private void Img_SetSOurce_cllearAll_Click(object sender, EventArgs e)
        {
            Image_MercurySetSource_result_show.Clear();
            Image_MercurySetSource_result_show.BackColor = Color.White;

        }
        private void Img_MercurySetSourceSelected_butt_Click(object sender, EventArgs e)
        {

            int id;
            Image_MercurySetSource_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, Image_MercurySetSource_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetMercurySourceType(Image_MercurySourceList_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        }


        #endregion


        #region Monitoring tab commands

        private void Mo_Get_All_Click(object sender, EventArgs e)
        {
            //Mo_getLogFile_butt_Click(null, null);
            //mo_Get_diagnostics_butt_Click(null, null);
            Mo_Get_stat_Click(null, null);
            Monitoring_GetFanSpeed_butt_Click(null, null);
            Monitoring_GetTemp_butt_Click(null, null);
            MO_GetRunTimes_Click(null, null);
            Monitoring_GetFanTicks_butt_Click(null, null);

        }


        private void Mo_Get_stat_Click(object sender, EventArgs e)
        {
            int id;
            textBox84.BackColor = Color.HotPink;
            
            
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox85, textBox83, textBox82);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_meminfo_get, textBox84, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_mem_info");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

           gui = new GuiBoxArray();
           gui.Add(textBox81, textBox79, textBox80);
           obj = new command_requestObj(Common.commandType.cmd_mo_loadinfo_get, textBox84, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_load_info");
            request_chain[id] = obj;

            Monitor.Exit(request_chain);




        }

        private void Mo_Get_stat_clearAll_Click(object sender, EventArgs e)
        {

        }
        private void MO_GetRunTimes_Click(object sender, EventArgs e)
        {
            int id;
            textBox67.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox74,textBox167, textBox23);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_runtimes_get, textBox67, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_run_times");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void mo_Getruntime_clear_Click(object sender, EventArgs e)
        {

        }
        private void Monitoring_GetFanSpeed_butt_Click(object sender, EventArgs e)
        {

            int id;
            Mo_SetFanSpeed_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Mo_SetSpeed_txtbox);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_get_fan_speed, Mo_SetFanSpeed_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetFanSpeed("fan1");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


            gui = new GuiBoxArray();
            gui.Add(textBox57);
             obj = new command_requestObj(Common.commandType.cmd_mo_get_fan_speed, Mo_SetFanSpeed_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetFanSpeed("fan2");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);





        }

        private void Monitoring_SetFanSpeed_butt_Click(object sender, EventArgs e)
        {
            int id;
            Mo_SetFanSpeed_Result_show.BackColor = Color.HotPink;

            if (Mo_fanSpeed_CheckBox_1.Checked)
            {
                command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, Mo_SetFanSpeed_Result_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetFanSpeed("fan1", Convert.ToInt32(Mo_SetSpeed_txtbox.Text));
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
            }


            if (Mo_fanSpeed_CheckBox_2.Checked)
            {
                command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_set, Mo_SetFanSpeed_Result_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetFanSpeed("fan2", Convert.ToInt32(textBox57.Text));
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
            }

        }


        private void Monitoring_GetTemp_butt_Click(object sender, EventArgs e)
        {
            int id;
            
            Mo_GetTemprature_result_Show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Mo_GetTemprature_Temp_Show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_temprature_get, Mo_GetTemprature_result_Show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetTemprature("mercury");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


            gui = new GuiBoxArray();
            gui.Add(textBox58);
             obj = new command_requestObj(Common.commandType.cmd_temprature_get, Mo_GetTemprature_result_Show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetTemprature("ops");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

            gui = new GuiBoxArray();
            gui.Add(textBox60);
            obj = new command_requestObj(Common.commandType.cmd_temprature_get, Mo_GetTemprature_result_Show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetTemprature("niro");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


            gui = new GuiBoxArray();
            gui.Add(textBox59);
            obj = new command_requestObj(Common.commandType.cmd_temprature_get, Mo_GetTemprature_result_Show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetTemprature("ambient");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

            gui = new GuiBoxArray();
            gui.Add(textBox61);
            obj = new command_requestObj(Common.commandType.cmd_temprature_get, Mo_GetTemprature_result_Show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetTemprature("smps");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


          

        }

        private void Monitoring_GetTemp_CleaAll_butt_Click(object sender, EventArgs e)
        {
            Mo_GetTemprature_result_Show.Clear();
            Mo_GetTemprature_Temp_Show.Clear();
            textBox58.Clear();
            textBox60.Clear();
            textBox59.Clear();
            textBox61.Clear();
            
            Mo_GetTemprature_result_Show.BackColor = Color.White;



        }
        private void Monitoring_GetFanRPM_butt_Click(object sender, EventArgs e)
        {

            int id;
            Mo_GetFanRPMResult_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_state_get, Mo_GetFanRPMResult_show);
            Monitor.Enter(request_chain);
            id = AllCommands.GetFanRpm(Mo_FanType_RPM_combo_Get.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }


        #endregion

        #region Network IF tab Commands

        private void Net_GetMac_intenal(string mac)
        {

            int id;
            command_requestObj obj = null;
           
            if(mac == "eth0")
                obj = new command_requestObj(Common.commandType.cmd_mac1_address_get_internal, textBox28888);
            else if (mac == "eth1")
                obj = new command_requestObj(Common.commandType.cmd_mac2_address_get_internal, textBox28888);
            Monitor.Enter(request_chain);
            id = AllCommands.GetMacAddress(mac);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }


        private void Net_Get_Netinfo_Click(object sender, EventArgs e)
        {
            int id;
            textBox77.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox78, textBox76, textBox75);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_net_NetInfo_get, textBox77, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetNetInfo("eth0");
            request_chain[id] = obj;

            textBox143.BackColor = Color.HotPink;
            gui = new GuiBoxArray();
             gui.Add(textBox138, textBox139, textBox134);
             obj = new command_requestObj(Common.commandType.cmd_net_NetInfo_get, textBox143, gui);
            
             id = AllCommands.GetNetInfo("eth1");
             request_chain[id] = obj;

             Monitor.Exit(request_chain);

        }

        private void Net_Get_Netinfo_clearAll_Click(object sender, EventArgs e)
        {
            textBox77.Clear();
            textBox77.BackColor = Color.White;
            textBox78.Clear();
            textBox75.Clear();
            textBox76.Clear();

            textBox143.Clear();
            textBox143.BackColor = Color.White;
            textBox138.Clear();
            textBox139.Clear();
            textBox134.Clear();

        }
        private void Net_Get_IpAddress_but_Click(object sender, EventArgs e)
        {
            int id;
            Net_getSetNicIF_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add( textBox71, textBox72);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_net_networkIf_get, Net_getSetNicIF_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetNetworkIf(Net_NicIf_eth_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Net_Set_IpAddress_but_Click(object sender, EventArgs e)
        {
            int id;
            Net_getSetNicIF_result_show.BackColor = Color.HotPink;
            command_requestObj obj;

            obj = new command_requestObj(Common.commandType.cmd_mac_address_set, Net_getSetNicIF_result_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetNetworkIf(Net_NicIf_eth_combo.Text, 
                                             Net_GetSetNetIf_Mode_combo.Text,
                                            textBox71.Text,
                                            textBox72.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
           


        }

        private void Net_IpAddress__clearALLbut_Click(object sender, EventArgs e)
        {
             textBox71.Clear(); textBox72.Clear();
            Net_getSetNicIF_result_show.Clear();
            Net_getSetNicIF_result_show.BackColor = Color.White;

        }


        private void NetIF_Get_All_Click(object sender, EventArgs e)
        {
            Net_GetMac_Click(null, null);
            Net_Get_IpAddress_but_Click(null, null);
            Net_Get_Netinfo_Click(null, null);

        }
        private void Net_GetMac_Click(object sender, EventArgs e)
        {

            int id;
            Net_Mac_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Net_Mac_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mac_address_get, Net_Mac_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetMacAddress("eth0");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


            gui = new GuiBoxArray();
            gui.Add(textBox62);
             obj = new command_requestObj(Common.commandType.cmd_mac_address_get, Net_Mac_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetMacAddress("eth1");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Net_SetMac_Click(object sender, EventArgs e)
        {
            int id;
            Net_Mac_result_show.BackColor = Color.HotPink;
            command_requestObj obj;

            if (Net_if_Mac1_check.Checked)
            {
                obj = new command_requestObj(Common.commandType.cmd_mac_address_set, Net_Mac_result_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetMacAddress("eth0", Net_Mac_show.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
            }

            if (Net_if_Mac2_check.Checked)
            {
                obj = new command_requestObj(Common.commandType.cmd_mac_address_set, Net_Mac_result_show);
                Monitor.Enter(request_chain);
                id = AllCommands.SetMacAddress("eth1", textBox62.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
            }

        }

        private void Net_ClearALl_Click(object sender, EventArgs e)
        {
            Net_Mac_result_show.Clear();
            Net_Mac_show.Clear();
            textBox62.Clear();
            Net_Mac_result_show.BackColor = Color.White;


        }

        #endregion

        #region dataBase tab Commands
        private void Gen_GetAutoSave_but_Click(object sender, EventArgs e)
        {
            int id;
            textBox86.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(GetSetAutoSave_combo);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_AutoSave_state_get, textBox86, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_auto_save");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Gen_SetAutoSave_but_Click(object sender, EventArgs e)
        {
            int id;
            textBox86.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_AutoSave_state_set, textBox86);
            Monitor.Enter(request_chain);
            id = AllCommands.SetAutoSave(GetSetAutoSave_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void Gen_GetAutoSave_but_clearAll_Click(object sender, EventArgs e)
        {
            textBox86.Clear();
            textBox86.BackColor = Color.White;

        }

        private void DB_saveAll_Click(object sender, EventArgs e)
        {
            int id;
            DB_saveAll_result_show.BackColor = Color.HotPink;

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_dataBase_saveAll, DB_saveAll_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.saveALL();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void DB_Get_all_Click(object sender, EventArgs e)
        {
            DB_Bid_Mercury_get_Click(null, null);
            DB_Niro_Bid_Get_Click(null, null);
            DB_Display_Bid_Get_Click(null, null);
        }

        private void DB_Bid_Mercury_get_Click(object sender, EventArgs e)
        {
            #region All Big Get
            int id;
            DB_BiD_Mercury_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(DB_Bid_data_txtbx);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "det_brd_desc");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox2);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "dev_artcl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox1);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "dev_prod_date");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(textBox6);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "dev_serl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
           // Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox5);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "id_ver_locn");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox4);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "id_ver_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(textBox3);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "mod_artcl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
           // Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(textBox10);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "mod_prod_date");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox9);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "mod_prod_indx");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox8);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_BiD_Mercury_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("mercury", "mod_serl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
           // Thread.Sleep(100);

            #endregion
        }

        private void DB_Bid_Mercury_Set_Click(object sender, EventArgs e)
        {
            #region All Big Set
            int id;
            DB_BiD_Mercury_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            command_requestObj obj = null;


            if (DB_Bid_data_txtbx.Text != "" && checkBox1.Checked)
            {
                 gui = new GuiBoxArray();
                gui.Add(DB_Bid_data_txtbx);
                 obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "det_brd_desc", DB_Bid_data_txtbx.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox2.Text != "" && checkBox2.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox2);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "dev_artcl_num", textBox2.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }


            if (textBox1.Text != "" && checkBox4.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox1);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "dev_prod_date", textBox1.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox6.Text != "" && checkBox3.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox6);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "dev_serl_num", textBox6.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox5.Text != "" && checkBox6.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox5);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "id_ver_locn", textBox5.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }




            if (textBox4.Text != "" && checkBox5.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox4);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "id_ver_num", textBox4.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox3.Text != "" && checkBox8.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox3);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "mod_artcl_num", textBox3.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox10.Text != "" && checkBox7.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox10);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "mod_prod_date", textBox10.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox9.Text != "" && checkBox10.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox9);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "mod_prod_indx", textBox9.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox8.Text != "" && checkBox9.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox8);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("mercury", "mod_serl_num", textBox8.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }


            #endregion
        }


        private void DB_Niro_Bid_Get_Click(object sender, EventArgs e)
        {
            #region All Big Get
            int id;
            DB_Niro_Bid_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox33);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "det_brd_desc");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox32);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "dev_artcl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox31);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "dev_prod_date");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(textBox30);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "dev_serl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox29);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "id_ver_locn");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox28);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "id_ver_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(textBox27);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "mod_artcl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(textBox26);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "mod_prod_date");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox25);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "mod_prod_indx");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox24);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Niro_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("niro", "mod_serl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            #endregion

        }

        private void DB_Niro_Bid_Set_Click(object sender, EventArgs e)
        {

            #region All Big Set
            int id;
            DB_Niro_Bid_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            command_requestObj obj = null;


            if (textBox33.Text != "" && checkBox20.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox33);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "det_brd_desc", textBox33.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox32.Text != "" && checkBox19.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox32);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "dev_artcl_num", textBox32.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }


            if (textBox31.Text != "" && checkBox18.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox31);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "dev_prod_date", textBox31.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox30.Text != "" && checkBox17.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox30);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "dev_serl_num", textBox30.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox29.Text != "" && checkBox16.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox29);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "id_ver_locn", textBox29.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }




            if (textBox28.Text != "" && checkBox15.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox28);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "id_ver_num", textBox28.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox27.Text != "" && checkBox14.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox27);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "mod_artcl_num", textBox27.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox26.Text != "" && checkBox13.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox26);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "mod_prod_date", textBox26.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox25.Text != "" && checkBox12.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox25);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "mod_prod_indx", textBox25.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox24.Text != "" && checkBox11.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox24);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Niro_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("niro", "mod_serl_num", textBox24.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }


            #endregion

        }

        private void DB_Niro_Bid_ClearAll_Click(object sender, EventArgs e)
        {
            DB_Niro_Bid_result_show.Clear();
            DB_Niro_Bid_result_show.BackColor = Color.White;

            textBox33.Clear();
            textBox33.BackColor = Color.White;

            textBox32.Clear();
            textBox32.BackColor = Color.White;


            textBox31.Clear();
            textBox31.BackColor = Color.White;

            textBox30.Clear();
            textBox30.BackColor = Color.White;
            textBox29.Clear();
            textBox29.BackColor = Color.White;

            textBox28.Clear();
            textBox28.BackColor = Color.White;
            textBox27.Clear();
            textBox27.BackColor = Color.White;
            textBox26.Clear();
            textBox26.BackColor = Color.White;
            textBox25.Clear();
            textBox25.BackColor = Color.White;
            textBox24.Clear();
            textBox24.BackColor = Color.White;
            
            

        }

        private void DB_Display_Bid_Get_Click(object sender, EventArgs e)
        {
            #region All Big Get
            int id;
            DB_Display_Bid_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox44);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "det_brd_desc");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox43);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "dev_artcl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox42);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "dev_prod_date");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(Db_Disp_bid_Serial_num);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "dev_serl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox40);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "id_ver_locn");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox39);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "id_ver_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(textBox38);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "mod_artcl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);


            gui = new GuiBoxArray();
            gui.Add(textBox37);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "mod_prod_date");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox36);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "mod_prod_indx");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            gui = new GuiBoxArray();
            gui.Add(textBox35);
            obj = new command_requestObj(Common.commandType.cmd_bid_get, DB_Display_Bid_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBid("display", "mod_serl_num");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Thread.Sleep(100);

            #endregion

        }

        private void DB_Display_Bid_Set_Click(object sender, EventArgs e)
        {
            #region All Big Set
            int id;
            DB_Display_Bid_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            command_requestObj obj = null;


            if (textBox44.Text != "" && checkBox30.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox44);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "det_brd_desc", textBox44.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox43.Text != "" && checkBox29.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox43);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "dev_artcl_num", textBox43.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }


            if (textBox42.Text != "" && checkBox28.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox42);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "dev_prod_date", textBox42.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (Db_Disp_bid_Serial_num.Text != "" && checkBox27.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(Db_Disp_bid_Serial_num);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "dev_serl_num", Db_Disp_bid_Serial_num.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox40.Text != "" && checkBox26.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox40);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "id_ver_locn", textBox40.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }




            if (textBox39.Text != "" && checkBox25.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox39);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "id_ver_num", textBox39.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox38.Text != "" && checkBox24.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox38);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "mod_artcl_num", textBox38.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox37.Text != "" && checkBox23.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox37);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "mod_prod_date", textBox37.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox36.Text != "" && checkBox22.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox36);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "mod_prod_indx", textBox36.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }

            if (textBox35.Text != "" && checkBox21.Checked)
            {
                gui = new GuiBoxArray();
                gui.Add(textBox35);
                obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_Display_Bid_result_show, gui);
                Monitor.Enter(request_chain);
                id = AllCommands.Setbid("display", "mod_serl_num", textBox35.Text);
                request_chain[id] = obj;
                Monitor.Exit(request_chain);
                Thread.Sleep(100);
            }


            #endregion

        }

        private void DB_Display_Bid_ClearAll_Click(object sender, EventArgs e)
        {
            DB_Display_Bid_result_show.Clear();
            DB_Display_Bid_result_show.BackColor = Color.White;

            textBox44.Clear();
            textBox44.BackColor = Color.White;

            textBox43.Clear();
            textBox43.BackColor = Color.White;


            textBox42.Clear();
            textBox42.BackColor = Color.White;

            Db_Disp_bid_Serial_num.Clear();
            Db_Disp_bid_Serial_num.BackColor = Color.White;
            textBox40.Clear();
            textBox40.BackColor = Color.White;

            textBox39.Clear();
            textBox39.BackColor = Color.White;
            textBox38.Clear();
            textBox38.BackColor = Color.White;
            textBox37.Clear();
            textBox37.BackColor = Color.White;
            textBox36.Clear();
            textBox36.BackColor = Color.White;
            textBox35.Clear();
            textBox35.BackColor = Color.White;
        }


        /*
        private void DB_Bid_Mercury_Set_Click(object sender, EventArgs e)
        {
            int id;
            DB_BiD_Mercury_Result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_bid_set, DB_BiD_Mercury_Result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.Setbid("mercury", "det_brd_desc", DB_Bid_data_txtbx.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }
        */
        private void DB_Bid_Mercury_ClearALl_Click(object sender, EventArgs e)
        {
            DB_BiD_Mercury_Result_show.Clear();
            DB_BiD_Mercury_Result_show.BackColor = Color.White;
            
            DB_Bid_data_txtbx.Clear();
            DB_Bid_data_txtbx.BackColor = Color.White;

            


            textBox1.Clear();
            textBox1.BackColor = Color.White;

            textBox2.Clear();
            textBox2.BackColor = Color.White;
            textBox6.Clear();
            textBox6.BackColor = Color.White;

            textBox5.Clear();
            textBox5.BackColor = Color.White;
            textBox4.Clear();
            textBox4.BackColor = Color.White;
            textBox3.Clear();
            textBox3.BackColor = Color.White;
            textBox10.Clear();
            textBox10.BackColor = Color.White;
            textBox9.Clear();
            textBox9.BackColor = Color.White;
            textBox8.Clear();
            textBox8.BackColor = Color.White;

        }
#endregion

        #region Hw Tab Commands
        private void Hw_Test_memory_devices_Test_start_Click(object sender, EventArgs e)
        {
            Hw_TestMemory_group.Enabled = false;
            int id;
            Hw_Test_memory_devices_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_test_memory, Hw_Test_memory_devices_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.Test_Memory(Hw_Test_memory_dev_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);



        }

        

        private void Hw_Test_memory_devices_Test_Clearall_Click(object sender, EventArgs e)
        {
            Hw_Test_memory_devices_result_show.Clear();
            Hw_Test_memory_devices_result_show.BackColor = Color.White;
        }


        private void Gen_User_logOut_button_Click(object sender, EventArgs e)
        {
            foreach (Button but in AdminButtons)
            {
                but.Enabled = false;

            }
            foreach (Button but in UserButtons)
            {
                but.Enabled = false;

            }
            Debuf_Encrypt_file.Visible = false;
            Debuf_Dycrypt_file.Visible = false;
            Wall_Wall_Config.Visible = false;
            UserType = String.Empty;
            ps171_bankRadio_box.Enabled = false;
            groupBox47.Visible = false;
            SpecialBut.Visible = false;
        }

        private void Hw_memory_test_enable_Click(object sender, EventArgs e)
        {
            
            if (AdminUser_txtBox.Text == "expert")
            {
                if (Hw_mem_test_Pass_box.Text == GetAuthExpert())
                {
                    foreach (Button but in AdminButtons)
                    {
                        but.Enabled = true;

                    }
                    foreach (Button but in UserButtons)
                    {
                        but.Enabled = true;

                    }
                    //KortexGuiMain. // change form Caption here 
                    UserType = AdminUser_txtBox.Text;
                    groupBox47.Visible = true;
                }
                else
                    MessageBox.Show("User Name And Password does not match");
            }
            else if (AdminUser_txtBox.Text == "user")
            {
                if (Hw_mem_test_Pass_box.Text == "barco")
                {
                    foreach (Button but in UserButtons)
                    {
                        but.Enabled = true;

                    }
                    //KortexGuiMain. // change form Caption here 
                    UserType = AdminUser_txtBox.Text;
                }

            }
            else if (AdminUser_txtBox.Text == "kp")
            {
                if (Hw_mem_test_Pass_box.Text == GetkpAuth())
                {
                    foreach (Button but in AdminButtons)
                    {
                        but.Enabled = true;

                    }
                    foreach (Button but in UserButtons)
                    {
                        but.Enabled = true;

                    }
                    //KortexGuiMain. // change form Caption here 
                    UserType = AdminUser_txtBox.Text;
                    Debuf_Encrypt_file.Visible = true;
                    Debuf_Dycrypt_file.Visible = true;
                   
                }
                
            }
            else if (AdminUser_txtBox.Text == "hack")
            {
                if (Hw_mem_test_Pass_box.Text == "hacking007")
                {
                    SpecialBut.Visible = true;
                }
            }
            else
            {
                Gen_User_logOut_button_Click(null, null);
                MessageBox.Show("User Name And Password does not match");

            }

            Hw_mem_test_Pass_box.Clear();
            AdminUser_txtBox.Clear();


        }
        #endregion


        #region FMW tab commands


        private void fmw_GetMstar_fmw_version_Click(object sender, EventArgs e)
        {
            int id;
            fmw_msta_ver_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox50);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_fmw_mstar_version_get, fmw_msta_ver_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetMstarFmwVersion();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void fmw_GetMstar_fmw_version_clearALl_Click(object sender, EventArgs e)
        {

        }

        private void FMW_Get_all_Click(object sender, EventArgs e)
        {
            fmw_version_Get_butt_Click(null, null);
            fmw_GetMstar_fmw_version_Click(null, null);

        }

        private void fmw_version_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            fmw_version_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(fmw_mercury_version);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mrc_spi_module_version_get, fmw_version_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetModuleVersion("MrcSpiProj");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
             
            gui = new GuiBoxArray();
            gui.Add(textBox54);
            obj = new command_requestObj(Common.commandType.cmd_module_version_get, fmw_version_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetModuleVersion("MrcFpga");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            


            gui = new GuiBoxArray();
            gui.Add(textBox56);
            obj = new command_requestObj(Common.commandType.cmd_module_version_get, fmw_version_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetModuleVersion("MrcPs171");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            


            gui = new GuiBoxArray();
            gui.Add(textBox55);
            obj = new command_requestObj(Common.commandType.cmd_module_version_get, fmw_version_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetModuleVersion("MrcStdp");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


            




            //fmw_version_result_show.Text = "In Progress";
        }


        private void fmw_version_ClearAll_butt_Click(object sender, EventArgs e)
        {
            fmw_mercury_version.Clear();
            textBox54.Clear();
            textBox56.Clear();
            textBox55.Clear();
            fmw_version_result_show.Clear();
            fmw_version_result_show.BackColor = Color.White;
        }

        #endregion



        

      

   

        #region Wakeon Lan
        private  void WakeUp(string ip_p,byte[] mac)
        {
            //
            // WOL packet is sent over UDP 255.255.255.0:40000.
            //
            byte []WOl = new byte [4];


            if (ip_p != "")
            {
                string[] Ip = ip_p.Split(".".ToCharArray());
                for (int i = 0; i < Ip.Length; i++)
                {
                    WOl[i] = byte.Parse(Ip[i], NumberStyles.Number);

                }
            }
            else
            {
                WOl[0] = 0xFF;
                WOl[1] = 0xFF;
                WOl[2] = 0xFF;
                WOl[3] = 0xFF;
            }

            IPAddress IPAddr = new IPAddress(WOl);
            UdpClient client = new UdpClient();
            client.Connect(IPAddr, 40000);

            //
            // WOL packet contains a 6-bytes trailer and 16 times a 6-bytes sequence containing the MAC address.
            //
            byte[] packet = new byte[17 * 6];

            //
            // Trailer of 6 times 0xFF.
            //
            for (int i = 0; i < 6; i++)
                packet[i] = 0xFF;

            //
            // Body of magic packet contains 16 times the MAC address.
            //
            for (int i = 1; i <= 16; i++)
                for (int j = 0; j < 6; j++)
                    packet[i * 6 + j] = mac[j];

            //
            // Submit WOL packet.
            //
            client.Send(packet, packet.Length);
        }

        private void CreateAndSendMagicPkt(string ip_p,string mac_p)
        {
            int i = 0;
            int counter = 0;
            byte[] bytes = new byte[10];   // more than enough :-)
            try
            {
                for (int z = 0; z < 6; z++)
                {
                    bytes[counter++] = byte.Parse(mac_p.Substring(i, 2), NumberStyles.HexNumber);
                    i += 3;
                }

                WakeUp(ip_p, bytes);
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);

            }
        
        }

        private void Brodcast_WOL_Click(object sender, EventArgs e)
        {

            CreateAndSendMagicPkt(WOL_IP_address_txtBox.Text, WOL_mac1_address_txtBox.Text);
            CreateAndSendMagicPkt(WOL_IP_address_txtBox.Text, WOL_mac2_address_txtBox.Text);
            CreateAndSendMagicPkt("", WOL_mac1_address_txtBox.Text);
            CreateAndSendMagicPkt("", WOL_mac2_address_txtBox.Text);

        }

        #endregion 

        private void WriteToFIle(string fileName, string data)
        {
            FileStream FStream = null;
            FStream = File.OpenWrite(fileName);
            FStream.Seek(0, SeekOrigin.Begin);


            FStream.Write(S2b(data), 0, data.Length);

            FStream.Close();
        
        }


        #region Debug Tab Commands
        private void RunSSH_cmd(Object cmd)
        {

            Ssh_command obj = (Ssh_command)cmd;
            string result = "sample";
            string command = obj.sshCmd;
            result = KpScpSshclt.kp_runCmd(txtBox_IP.Text,command , GetDyki());
           

            FileInfo MyFile = new FileInfo(localDir + "\\Result.txt");
            MyFile.Delete();


              WriteToFIle(localDir+"\\Result.txt", result);


           /* Debug_Start_GenLock.Enabled = true;
            Debug_SetGama.Enabled = true;
            * */
           KpScpSshclt.kp_runCmd(txtBox_IP.Text, "rm -rf " + obj.sshRemote, GetDyki());  
            obj.butStatus = true;

        
        }



        private bool CheckGenLockFile()
        {

            FileStream FStream = null;
            FStream = File.OpenRead(localDir + "\\genlock_test.sh");
            int count = 0;
            byte[] Buff = new Byte[FStream.Length];
            count = FStream.Read(Buff, 0, (Int32)FStream.Length);
            FStream.Close();
            string script = System.Text.ASCIIEncoding.ASCII.GetString(Buff);

            script = Enc_dec.Encrypt(script, "Barco");

            WriteToFIle(localDir + "\\Script.sh", script);


            script = Enc_dec.Decrypt(script, "Barco");

            WriteToFIle(localDir + "\\Script_final.sh", script);

            return true;
        
        }

        private void EncryptFIle(string sourceFle, string targetFile, string password)
        {
            FileStream FStream = null;
            FStream = File.OpenRead(sourceFle);
            int count = 0;
            byte[] Buff = new Byte[FStream.Length];
            count = FStream.Read(Buff, 0, (Int32)FStream.Length);
            FStream.Close();
            FileInfo MyFile = new FileInfo(targetFile);
            if (MyFile.Exists)
                MyFile.Delete();

            string script = System.Text.ASCIIEncoding.ASCII.GetString(Buff);

            string result = Enc_dec.Encrypt(script, password);

            WriteToFIle(targetFile, result);

        
        }

        private void DycryptFIle(string sourceFle,string targetFile ,string password)
        {
            FileStream FStream = null;
            FStream = File.OpenRead(sourceFle);
            int count = 0;
            byte[] Buff = new Byte[FStream.Length];
            count = FStream.Read(Buff, 0, (Int32)FStream.Length);
            FStream.Close();
            FileInfo MyFile = new FileInfo(targetFile);
            if(MyFile.Exists)
            MyFile.Delete();

            string script = System.Text.ASCIIEncoding.ASCII.GetString(Buff);

            string result = Enc_dec.Decrypt(script, password);

            WriteToFIle(targetFile, result);


        }


        private void button3_Click(object sender, EventArgs e)
        {
            Thread T;
            string dyKI = GetDyki();

            DycryptFIle(localDir + "\\genlock_test_enc.sh", localDir + "\\genlock_test_dnc.sh", "this is new pass");
            KpScpSshclt.kp_scp(txtBox_IP.Text, localDir + "\\genlock_test_dnc.sh", "/tmp/genlock_test.sh", dyKI);
            FileInfo MyFile = new FileInfo(localDir + "\\genlock_test_dnc.sh");
                MyFile.Delete();

            KpScpSshclt.kp_runCmd(txtBox_IP.Text, "chmod +x /tmp/genlock_test.sh", dyKI);

            Debug_Start_GenLock.Enabled = false;
            Ssh_command obj = new Ssh_command("/tmp/genlock_test.sh", Debug_Start_GenLock, "/tmp/genlock_test.sh");

            T = new Thread(RunSSH_cmd);


            T.Start(obj);

           


        }

        private void Debug_Stop_GenLock_Click(object sender, EventArgs e)
        {
            KpScpSshclt.kp_runCmd(txtBox_IP.Text, "killall -9 genlock_test.sh", GetDyki());

        }


        #endregion


        #region Encryption/Dcryption
        private void Debuf_Encrypt_file_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName != "")
            {
                EncryptFIle(openFileDialog1.FileName, "ecrypt.txt", "God is great");
            }
        }

        private void Debuf_Dycrypt_file_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName != "")
            {
                DycryptFIle(openFileDialog1.FileName, "decrypt.txt", "God is great");
            }
        }

        #endregion


        #region Debug Tab Commands

        private void Debug_SaveTransctions_butt_Click(object sender, EventArgs e)
        {
            //List<ReqRespDebugInfo> req_responceDebug = new List<ReqRespDebugInfo>();
            saveFileDialog1.ShowDialog();
            string result = string.Empty;

            if (saveFileDialog1.FileName != "")
            {
                FileStream FStream = null;
                FStream = File.OpenWrite(saveFileDialog1.FileName);
                FStream.Seek(0, SeekOrigin.Begin);

                foreach (ReqRespDebugInfo obj in req_responceDebug)
                {
                    if (obj.cmd_type == reqResType.type_req)
                        result = ("-->|" + obj.mJson + "| at time " + obj.Time.Hour + ":" + obj.Time.Minute + ":" + obj.Time.Second + "." + obj.Time.Millisecond + "\n");
                    else if (obj.cmd_type == reqResType.type_res)
                        result = ("<--|" + obj.mJson + "| at time " + obj.Time.Hour + ":" + obj.Time.Minute + ":" + obj.Time.Second + "." + obj.Time.Millisecond + "\n");

                    FStream.Write(S2b(result), 0, result.Length);
                }
                FStream.Close();

            }
        }

        private void Debug_SetGama_Click(object sender, EventArgs e)
        {
            Thread T;
            string dyKI = GetDyki();
            openFileDialog1.ShowDialog();

            Debug_SetGama.Enabled = false;
            
            /*
            DycryptFIle(localDir + "\\uploadGama_enc.sh", localDir + "\\uploadGama_dnc.sh", "this is new pass");
            KpScpSshclt.kp_scp(txtBox_IP.Text, localDir + "\\uploadGama_dnc.sh", "/tmp/uploadGama.sh", dyKI);
            FileInfo MyFile = new FileInfo(localDir + "\\uploadGama_dnc.sh");
            MyFile.Delete();
            */

            if(openFileDialog1.FileName == "")
            KpScpSshclt.kp_scp(txtBox_IP.Text, localDir + "\\Gamma_3.0.txt", "/tmp/Gamma_3.0.txt", dyKI);
            else
                KpScpSshclt.kp_scp(txtBox_IP.Text, openFileDialog1.FileName, "/tmp/Gamma_3.0.txt", dyKI);


            //KpScpSshclt.kp_runCmd(txtBox_IP.Text, "chmod +x /tmp/uploadGama.sh", dyKI);
            //KpScpSshclt.kp_runCmd(txtBox_IP.Text, "/tmp/uploadGama.sh /tmp/Gamma_3.0.txt", dyKI);

            Ssh_command obj = new Ssh_command("/opt/fmw/bin/uploadGamma.sh /tmp/Gamma_3.0.txt", Debug_SetGama, "/tmp/Gamma_3.0.txt");

            T = new Thread(RunSSH_cmd);
            T.Start(obj);

        }

        private void img_background_combo_SelectedIndexChanged(object sender, EventArgs e)
        {
            /*if (img_background_combo.Text == "custom" || img_background_combo.Text == "custom.")
                Img_Color_GroupBox.Visible = true;
            else
                Img_Color_GroupBox.Visible = false;

            if (img_background_combo.Text == "custom")
            {
                textBox51.Text = Img_Color_picker_show_panel.BackColor.R.ToString();
                textBox52.Text = Img_Color_picker_show_panel.BackColor.G.ToString();
                textBox53.Text = Img_Color_picker_show_panel.BackColor.B.ToString();
            }
          */
            
        }


        #region Wall Manager
        private void Wall_createWall_Click(object sender, EventArgs e)
        {
            //Kortex.WallMgr  
            WallManager kp;
            //WallManager kp = new WallManager(Convert.ToInt32(Wall_Num_col.Text), Convert.ToInt32(Wall_Num_Row.Text), this, Wall_Input_slect.Text, Wall_mode_slect.Text);
            //CreateWallManager
            kp = Factory.Factory.CreateWallManager(Convert.ToInt32(Wall_Num_col.Text), Convert.ToInt32(Wall_Num_Row.Text), this, Wall_Input_slect.Text, Wall_mode_slect.Text);
            kp.Show();

        }

        private void Wall_LoadWall_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "WallConfig File|*.wall";
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName != "")
            {
                FileInfo MyFile = new FileInfo(openFileDialog1.FileName);
                if (MyFile.Exists)
                {
                    FileStream FStream = null;
                    FStream = File.OpenRead(openFileDialog1.FileName);
                    int count = 0;
                    byte[] Buff = new Byte[FStream.Length];
                    count = FStream.Read(Buff, 0, (Int32)FStream.Length);
                    FStream.Close();
                    string Wall = System.Text.ASCIIEncoding.ASCII.GetString(Buff);

                    WallManager kp = Factory.Factory.CreateWallManager(Wall, this);
                    
                    if(kp != null)
                    kp.Show();
                    else
                        MessageBox.Show("Seems old verison of wall config used","ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  

                }
            }

        }

        private void Wall_LoadPriviuosWall_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "WallConfig File|*.wall";
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName != "")
            {
                FileInfo MyFile = new FileInfo(openFileDialog1.FileName);
                if (MyFile.Exists)
                {
                    FileStream FStream = null;
                    FStream = File.OpenRead(openFileDialog1.FileName);
                    int count = 0;
                    byte[] Buff = new Byte[FStream.Length];
                    count = FStream.Read(Buff, 0, (Int32)FStream.Length);
                    FStream.Close();
                    string Wall = System.Text.ASCIIEncoding.ASCII.GetString(Buff);

                    WallManager kp = Factory.Factory.CreateWallManagerSerialWise(Wall, this);

                    if (kp != null)
                        kp.Show();
                    else
                        MessageBox.Show("Seems old verison of wall config used", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);


                }
            }

        }

        private void Debug_Dump_transaction_Click(object sender, EventArgs e)
        {
            //List<ReqRespDebugInfo> req_responceDebug = new List<ReqRespDebugInfo>();
            saveFileDialog1.ShowDialog();
            string result = string.Empty;

            if (saveFileDialog1.FileName != "")
            {
                FileStream FStream = null;
                FStream = File.OpenWrite("trans_enc.txt");
                FStream.Seek(0, SeekOrigin.Begin);

                foreach (ReqRespDebugInfo obj in req_responceDebug)
                {
                    if (obj.cmd_type == reqResType.type_req)
                        result = ("-->" + obj.mJson + " at time " + obj.Time.Hour + ":" + obj.Time.Minute + ":" + obj.Time.Second + "." + obj.Time.Millisecond + "\n");
                    else if (obj.cmd_type == reqResType.type_res)
                        result = ("<--" + obj.mJson + " at time " + obj.Time.Hour + ":" + obj.Time.Minute + ":" + obj.Time.Second + "." + obj.Time.Millisecond + "\n");

                    FStream.Write(S2b(result), 0, result.Length);
                }
                FStream.Close();

                EncryptFIle("trans_enc.txt",saveFileDialog1.FileName, "this is new pass");
                FileInfo MyFile = new FileInfo("trans_enc.txt");
                MyFile.Delete();
               



            }

        }

        #endregion


        private void Debug_send_receive_Click(object sender, EventArgs e)
        {
           // if (DebugWindowObj == null)
            DebugWindowObj = new TransctionViewer(req_responceDebug,this);
            DebugWindowObj.Show();
        }
        #endregion

        #region ops tab commands

        private void Ops_Control_Panel_refresh_Click(object sender, EventArgs e)
        {
            
            int id;
          
            GuiBoxArray gui = null;

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_ops_power_state_get, img_wallConfig_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_ops_power_state");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);


            obj = new command_requestObj(Common.commandType.cmd_ops_fan_state_get, img_wallConfig_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_ops_fan_state");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);


            obj = new command_requestObj(Common.commandType.cmd_ops_plug_state_get, img_wallConfig_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_ops_plug_state");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            //Thread.Sleep(100);
           
        }

        private void ops_Get_all_Click(object sender, EventArgs e)
        {
            ops_GetOpState_but_Click(null, null);

        }

        private void ops_GetOpState_but_Click(object sender, EventArgs e)
        {
            int id;
            ops_GetSetOperation_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(ops_SeoGet_OPeration);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_ops_operationt_get, ops_GetSetOperation_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_ops_operation");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            Ops_Control_Panel_refresh_Click(null, null);

        }

        private void ops_SetOpState_but_Click(object sender, EventArgs e)
        {
            int id;


            ops_GetSetOperation_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_ops_operationt_set, ops_GetSetOperation_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.Setops_Operation(ops_SeoGet_OPeration.Text);
            
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void ops_tOpState_but_clearAll_Click(object sender, EventArgs e)
        {
            ops_GetSetOperation_result_show.Clear();
            ops_GetSetOperation_result_show.BackColor = Color.White;

        }


        #endregion


        #region GObal Led 
        private void Recorder_Led_Click(object sender, EventArgs e)
        {
            if (bRecoder)
            {
                Recorder_Tip.ToolTipTitle = "Off";
                Recorder_Led.Blink(0);
                Recorder_Led.Color = Color.Gray;
                bRecoder = false;

            }
            else
            {
                Recorder_Tip.ToolTipTitle = "On";
                Recorder_Led.Blink(1000);
                Recorder_Led.Color = Color.Red;
                bRecoder = true;
            }


        }

        private void System_tray_minimazer_Led_Click(object sender, EventArgs e)
        {
            //bTrayMiniMaize
            if (bTrayMiniMaize)
            {
                System_tran_COntrol_tip.ToolTipTitle = "off";
                bTrayMiniMaize = false;
                System_tray_minimazer_Led.Color = Color.Gray;
                
            }
            else
            {

                System_tran_COntrol_tip.ToolTipTitle = "on";
                bTrayMiniMaize = true;
                System_tray_minimazer_Led.Color = Color.PaleGreen;
                
            }

            kpDb.Set_WallMgr_table_val("SendToTrayCube", bTrayMiniMaize.ToString());
            kpDb.Commit_wallMgr_Table();
        }

        private void AutoUpdate_Led_Click(object sender, EventArgs e)
        {
            if (bAutoUpdate)
            {
                AutoUpdate_tip.ToolTipTitle = "off";
                bAutoUpdate = false;
                AutoUpdate_Led.Color = Color.Gray;
            }
            else
            {
               
                AutoUpdate_tip.ToolTipTitle = "on";
                bAutoUpdate = true;
                AutoUpdate_Led.Color = Color.PaleGreen;
            }

        }


        private void GlobalLedsInit()
        {
            // bool bRecoder = false;
            //  bool bAutoUpdate = true;
            Recorder_Tip.SetToolTip(Recorder_Led, "Recorder");
            AutoUpdate_tip.SetToolTip(AutoUpdate_Led, "Auto Update");
            System_tran_COntrol_tip.SetToolTip(System_tray_minimazer_Led, "Send to Tray at Minimize");
            Recorder_Tip.ToolTipTitle = "off";
            AutoUpdate_tip.ToolTipTitle = "on";
            System_tran_COntrol_tip.ToolTipTitle = "off";
           

        }

        #endregion

        #region Rooting Commands
        /*
        private void hack_hack(string Ip)
        {
            string dyKI = GetDyki();

            DycryptFIle(localDir + "\\hack_1", localDir + "\\tbd_1.bin", "God is great");
            KpScpSshclt.kp_scpRND(Ip, localDir + "\\tbd_1.bin", "/tmp/sudoers", dyKI);
            FileInfo MyFile = new FileInfo(localDir + "\\tbd_1.bin");
            MyFile.Delete();

            DycryptFIle(localDir + "\\hack_2", localDir + "\\tbd_2.bin", "God is great");
            KpScpSshclt.kp_scpRND(Ip, localDir + "\\tbd_2.bin", "/tmp/kproot.sh", dyKI);
            MyFile = new FileInfo(localDir + "\\tbd_2.bin");
            MyFile.Delete();

            KpScpSshclt.kp_runCmdRND(Ip, "chmod +x /tmp/kproot.sh", dyKI);

            KpScpSshclt.kp_runCmdRND(Ip, "sudo /tmp/kproot.sh", dyKI);
            KpScpSshclt.kp_runCmdRND(Ip, "rm -rf /tmp/kproot.sh", dyKI);
        
        }
         * */
        private void SpecialBut_Click(object sender, EventArgs e)
        {
            /*string dyKI = GetDyki();

            DycryptFIle(localDir + "\\hack_1", localDir + "\\tbd_1.bin", "God is great");
            KpScpSshclt.kp_scpRND(txtBox_IP.Text, localDir + "\\tbd_1.bin", "/tmp/sudoers", dyKI);
            FileInfo MyFile = new FileInfo(localDir + "\\tbd_1.bin");
           MyFile.Delete();

           DycryptFIle(localDir + "\\hack_2", localDir + "\\tbd_2.bin", "God is great");
           KpScpSshclt.kp_scpRND(txtBox_IP.Text, localDir + "\\tbd_2.bin", "/tmp/kproot.sh", dyKI);
            MyFile = new FileInfo(localDir + "\\tbd_2.bin");
           MyFile.Delete();

           KpScpSshclt.kp_runCmdRND(txtBox_IP.Text, "chmod +x /tmp/kproot.sh", dyKI);

           KpScpSshclt.kp_runCmdRND(txtBox_IP.Text, "sudo /tmp/kproot.sh", dyKI);
           KpScpSshclt.kp_runCmdRND(txtBox_IP.Text, "rm -rf /tmp/kproot.sh", dyKI);
             * */

           // hack_hack(txtBox_IP.Text);
            /*hack_hack("10.64.16.210");
            hack_hack("10.64.16.154");
            hack_hack("10.64.16.238");
             * */
            //hack_hack("10.128.64.212");


            SpecialBut.Visible = false;
            
           //KpScpSshclt.kp_runCmdRND(txtBox_IP.Text, "sudo passwd root", dyKI);

           //KpScpSshclt.kp_root(txtBox_IP.Text, "ls -lrt /tmp", dyKI);


        }
        #endregion

        #region Color Managament tab Commands

        private void CS_RawCount_get_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_raw_get_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox13, //sensor 0 status
                    textBox20, //sensor 1 status
                    textBox12, // Sensor 0 red
                    textBox11, // Sensor 0 green
                    textBox7,  // Sensor 0 blue
                    textBox15, // Sensor 0 white
                    textBox18, // Sensor 1 red
                    textBox19, // Sensor 1 green
                    textBox17, // Sensor 1 blue
                    textBox16);// Sensor 1 white

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_raw_count_get, CS_raw_get_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_CSRaw_count_();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_RawCount_get_ClearALlbutt_Click(object sender, EventArgs e)
        {
            CS_raw_get_result_show.Clear();
            CS_raw_get_result_show.BackColor = Color.White;
            textBox13.Clear();
            textBox20.Clear();
            textBox12.Clear();
            textBox11.Clear();
            textBox7.Clear();
            textBox15.Clear();
            textBox18.Clear();
            textBox19.Clear();
            textBox17.Clear();
            textBox16.Clear();
        }

     

        private void CS_Get_cs_params_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_params_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(Cs_param_Gain_combo,
                    Cs_param_Prescaler_combo,
                    Cs_param_Period_combo,
                    Cs_param_Pulse_combo);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_params_get, CS_params_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("get_cs_params");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void CS_Set_cs_params_butt_Click(object sender, EventArgs e)
        {
            int id;
            int gain = Convert.ToInt32(Cs_param_Gain_combo.Text);
            int prescale = Convert.ToInt32(Cs_param_Prescaler_combo.Text);
            

            CS_params_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wallConfig_set, CS_params_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetColorSensor_params(gain, prescale, Cs_param_Period_combo.Text, Cs_param_Pulse_combo.Text);
            
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void CS_Get_cs_params_ClearAll_butt_Click(object sender, EventArgs e)
        {
            CS_params_result_show.Clear();
            CS_params_result_show.BackColor = Color.White;

        }

        private void CS_BackLight_slider_Scroll(object sender, EventArgs e)
        {
            cs_back_light_show.Text = CS_BackLight_slider.Value.ToString();
        }

        private void cs_backLight_set_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox14.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_backLight_set, textBox14);
            Monitor.Enter(request_chain);
            id = AllCommands.SetBackLight_via_cs(Convert.ToInt32(cs_back_light_show.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void cs_backLight_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox14.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(cs_back_light_show);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_backLight_get, textBox14, CS_BackLight_slider, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetBackLight_Via_cs();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void cs_Back_light_status_get_butt_Click(object sender, EventArgs e)
        {
            int id;

            cs_backlight_status_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(cs_backLight_status_combo);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_backLight_status_get, cs_backlight_status_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("get_bklight_status");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void cs_Back_light_status_Set_butt_Click(object sender, EventArgs e)
        {
            int id;
            cs_backlight_status_result_show.BackColor = Color.HotPink;
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_backLight_status_set, cs_backlight_status_result_show);
            Monitor.Enter(request_chain);
            id = AllCommands.SetColor_sensor_BackLight_status(cs_backLight_status_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void cs_Back_light_status_ClearALl_butt_Click(object sender, EventArgs e)
        {

        }

        private void CS_Mes_Loop_time_Get_butt_Click(object sender, EventArgs e)
        {
            


        }

        private void CS_Mes_Loop_time_Set_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_Loop_time_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            /*
            gui.Add(textBox21, textBox22);
            */
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_loop_time_set, CS_Loop_time_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.SetColor_sensor_Mes_Loop_time(CS_Mes_loop_time_status_combo.Text, textBox22.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_Mes_Loop_time_ClearALl_butt_Click(object sender, EventArgs e)
        {
            CS_Loop_time_result_show.Clear();
            CS_Loop_time_result_show.BackColor = Color.White;

        }


       

        private void CS_Raw_CIS_get_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_raw_CIS_get_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox96, //sensor 0 status
                    textBox91, //sensor 1 status
                    textBox94, // Sensor 0 red
                    textBox95, // Sensor 0 green
                    textBox93,  // Sensor 0 blue
                    textBox92, // Sensor 0 white
                    textBox89, // Sensor 1 red
                    textBox90, // Sensor 1 green
                    textBox88, // Sensor 1 blue
                    textBox21);// Sensor 1 white


            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_raw_mes_cis_get, CS_raw_CIS_get_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_CSRaw_mes_cis();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_Raw_CIS__ClearAll_butt_Click(object sender, EventArgs e)
        {
            CS_raw_CIS_get_result_show.Clear();
            CS_raw_CIS_get_result_show.BackColor = Color.White;
            textBox96.Clear();
            textBox91.Clear();
            textBox94.Clear();
            textBox95.Clear();
            textBox93.Clear();
            textBox92.Clear();
            textBox89.Clear();
            textBox90.Clear();
            textBox88.Clear();
            textBox21.Clear();

        }

        private void CS_BackLight_mes_get_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_BackLIght__result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox106, //sensor 0 status
                    textBox101, //sensor 1 status
                    textBox104, // Sensor 0 red
                    textBox105, // Sensor 0 green
                    textBox103,  // Sensor 0 blue
                    textBox102, // Sensor 0 white
                    textBox99, // Sensor 1 red
                    textBox100, // Sensor 1 green
                    textBox98, // Sensor 1 blue
                    textBox97);// Sensor 1 white

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_backlight_mes_get, CS_BackLIght__result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_CS_backLIght_get();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_BackLight_mes_n_updateget_butt_Click(object sender, EventArgs e)
        {
             int id;

            CS_BackLIght__result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox106, //sensor 0 status
                    textBox101, //sensor 1 status
                    textBox104, // Sensor 0 red
                    textBox105, // Sensor 0 green
                    textBox103,  // Sensor 0 blue
                    textBox102, // Sensor 0 white
                    textBox99, // Sensor 1 red
                    textBox100, // Sensor 1 green
                    textBox98, // Sensor 1 blue
                    textBox97);// Sensor 1 white

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_backlight_mes_update_get, CS_BackLIght__result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_CS_backLIght_update_get();
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            
            

        }

        private void CS_BackLight_mes_ClearAll_butt_Click(object sender, EventArgs e)
        {
            CS_BackLIght__result_show.Clear();
            CS_BackLIght__result_show.BackColor = Color.White;
            textBox106.Clear();
            textBox101.Clear();
            textBox104.Clear();
            textBox105.Clear();
            textBox103.Clear();
            textBox102.Clear();
            textBox99.Clear();
            textBox100.Clear();
            textBox98.Clear();
            textBox97.Clear();

        }

        private void CS_Get_Field_calibration_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_Get_Reset_Field_Calibration_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox107, //RED X
                    textBox109, //RED Y
                    textBox110, // RED Z
                    textBox113, //GREEN X
                    textBox112,  //GREEN Y
                    textBox111, // GREEN Z
                    textBox116, //BLUE X
                    textBox115, //BLUE Y
                    textBox114 // BLUE Z
                             );

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_field_calib_get, CS_Get_Reset_Field_Calibration_Result_show, gui);
            Monitor.Enter(request_chain);
            
            if (CS_Get_reset_Field_calibration_Radio_CS0.Checked)
             id = AllCommands.GetGeneric_ColorSensor("get_field_calibration_cs0");
            else
             id = AllCommands.GetGeneric_ColorSensor("get_field_calibration_cs1");

            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void CS_Reset_Field_calibration_butt_Click(object sender, EventArgs e)
        {
            int id;

            DialogResult result = MessageBox.Show( "Do you really wish to reset field calibration","CAUTION !!",MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {

                CS_Get_Reset_Field_Calibration_Result_show.BackColor = Color.HotPink;
                command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_field_calib_reset, CS_Get_Reset_Field_Calibration_Result_show);
                Monitor.Enter(request_chain);

                if (CS_Get_reset_Field_calibration_Radio_CS0.Checked)
                    id = AllCommands.ReSetField_calibration("set_field_calibration_cs0");
                else
                    id = AllCommands.ReSetField_calibration("set_field_calibration_cs1");


                request_chain[id] = obj;
                Monitor.Exit(request_chain);
            }
        }

        private void CS_Field_calibration_ClearALLbutt_Click(object sender, EventArgs e)
        {
            CS_Get_Reset_Field_Calibration_Result_show.Clear();
            CS_Get_Reset_Field_Calibration_Result_show.BackColor = Color.White;
            textBox107.Clear();
            textBox109.Clear();
            textBox110.Clear();
            textBox113.Clear();
            textBox112.Clear();
            textBox111.Clear();
            textBox116.Clear();
            textBox115.Clear();
            textBox114.Clear();

        }

        private void CS_Get_Factory_calibration_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_Get_Reset_Factory_Calibration_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox125, //RED X
                    textBox124, //RED Y
                    textBox123, // RED Z
                    textBox122, //GREEN X
                    textBox121,  //GREEN Y
                    textBox120, // GREEN Z
                    textBox119, //BLUE X
                    textBox118, //BLUE Y
                    textBox117 // BLUE Z
                             );
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_factory_calib_get, CS_Get_Reset_Factory_Calibration_Result_show, gui);
            Monitor.Enter(request_chain);

            if (CS_Get_reset_Factory_calibration_Radio_CS0.Checked)
                id = AllCommands.GetGeneric_ColorSensor("get_factory_calibration_cs0");
            else
                id = AllCommands.GetGeneric_ColorSensor("get_factory_calibration_cs1");

            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_Factory_calibration_ClearALLbutt_Click(object sender, EventArgs e)
        {
            CS_Get_Reset_Factory_Calibration_Result_show.Clear();
            CS_Get_Reset_Factory_Calibration_Result_show.BackColor = Color.White;
            textBox107.Clear();
            textBox109.Clear();
            textBox110.Clear();
            textBox113.Clear();
            textBox112.Clear();
            textBox111.Clear();
            textBox116.Clear();
            textBox115.Clear();
            textBox114.Clear();

        }

      

        private void CS_ext_ref_data_get_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_Ext_ref_data_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox133, //Date
                    textBox132, //"proddata"
                    textBox131, //"processVer"
                    textBox137, //RED X
                    textBox136, //RED Y
                    textBox135, // RED Z
                    textBox130, //GREEN X
                    textBox129,//GREEN Y
                    textBox128,//GREEN Z
                    textBox127,  //BLUE X 
                    textBox126,  //BLUE Y
                    textBox108 // BLUE Z
                    );
            command_requestObj obj = null;
            Monitor.Enter(request_chain);

            if (CS_ext_ref_data_Field_Radio__butt.Checked)
            {
                obj = new command_requestObj(Common.commandType.cmd_cs_ext_field_ref_data_get, CS_Ext_ref_data_result_show, gui);
                id = AllCommands.GetGeneric_ColorSensor("get_external_field_cs_ref_data");
            }
            else
            {
                obj = new command_requestObj(Common.commandType.cmd_cs_ext_factory_ref_data_get, CS_Ext_ref_data_result_show, gui);
                id = AllCommands.GetGeneric_ColorSensor("get_external_factory_cs_ref_data");
            }

            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void CS_ext_ref_data_Set_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_Ext_ref_data_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            /*
            gui.Add(textBox21, textBox22);
            */
            command_requestObj obj = null;

            Monitor.Enter(request_chain);

            if (CS_ext_ref_data_Field_Radio__butt.Checked)
            {
                obj = new command_requestObj(Common.commandType.cmd_cs_ext_field_ref_data_set, CS_Ext_ref_data_result_show, gui);
                id = AllCommands.Set_External_Ref_data("set_external_field_cs_ref_data",
                                                       textBox133.Text,
                                                        textBox132.Text,
                                                        textBox131.Text,
                                                        Convert.ToDouble(textBox137.Text),
                                                        Convert.ToDouble(textBox136.Text),
                                                        Convert.ToDouble(textBox135.Text),
                                                        Convert.ToDouble(textBox130.Text),
                                                        Convert.ToDouble(textBox129.Text),
                                                        Convert.ToDouble(textBox128.Text),
                                                         Convert.ToDouble(textBox127.Text),
                                                        Convert.ToDouble(textBox126.Text),
                                                        Convert.ToDouble(textBox108.Text)
                                                        );
            }
            else
            {
                obj = new command_requestObj(Common.commandType.cmd_cs_ext_factory_ref_data_set, CS_Ext_ref_data_result_show, gui);
                id = AllCommands.Set_External_Ref_data("set_external_factory_cs_ref_data",
                                                       textBox133.Text,
                                                        textBox132.Text,
                                                        textBox131.Text,
                                                        Convert.ToDouble(textBox137.Text),
                                                        Convert.ToDouble(textBox136.Text),
                                                        Convert.ToDouble(textBox135.Text),
                                                        Convert.ToDouble(textBox130.Text),
                                                        Convert.ToDouble(textBox129.Text),
                                                        Convert.ToDouble(textBox128.Text),
                                                         Convert.ToDouble(textBox127.Text),
                                                        Convert.ToDouble(textBox126.Text),
                                                        Convert.ToDouble(textBox108.Text)
                                                        );
            }
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void CS_ext_ref_data_ClearAll_butt_Click(object sender, EventArgs e)
        {
            CS_Ext_ref_data_result_show.Clear();
            CS_Ext_ref_data_result_show.BackColor = Color.White;
        }
       

        private void CS_int_ref_data_get_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_int_ref_data_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox148, //RED 0
                    textBox147, //green 0
                    textBox146, // blue 0
                    textBox142, //red 1
                    textBox141,  //GREEN 1
                    textBox140 // blue 1
                    );


            command_requestObj obj = null;
            Monitor.Enter(request_chain);

            if (CS_int_ref_data_Field_Radio__butt.Checked)
            {
                obj = new command_requestObj(Common.commandType.cmd_cs_int_field_ref_data_get, CS_int_ref_data_result_show, gui);
                id = AllCommands.GetGeneric_ColorSensor("get_internal_field_cs_ref_data");
            }
            else
            {
                obj = new command_requestObj(Common.commandType.cmd_cs_int_factory_ref_data_get, CS_int_ref_data_result_show, gui);
                id = AllCommands.GetGeneric_ColorSensor("get_internal_factory_cs_ref_data");
            }

            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_int_ref_data_Set_butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_int_ref_data_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            /*
            gui.Add(textBox21, textBox22);
            */
            command_requestObj obj = null;

            Monitor.Enter(request_chain);

            if (CS_int_ref_data_Field_Radio__butt.Checked)
            {
                obj = new command_requestObj(Common.commandType.cmd_cs_int_field_ref_data_set, CS_int_ref_data_result_show, gui);
                id = AllCommands.Set_internal_Ref_data("set_internal_field_cs_ref_data");
            }
            else
            {
                obj = new command_requestObj(Common.commandType.cmd_cs_int_factory_ref_data_set, CS_int_ref_data_result_show, gui);
                id = AllCommands.Set_internal_Ref_data("set_internal_factory_cs_ref_data");
            }
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void button4_Click(object sender, EventArgs e)
        {
            CS_int_ref_data_result_show.Clear();
            CS_int_ref_data_result_show.BackColor = Color.White;

        }

        

        private void CS_Calibration_XYZ_Mes_Butt_Click(object sender, EventArgs e)
        {
            int id;

            CS_Calib_XYZ_Mes_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();

            gui.Add(textBox149, textBox145, textBox144);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_Calibrated_XYZ_get, CS_Calib_XYZ_Mes_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetCalib_XYZ_device(CS_Clib_XYZ_Device_type_combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void CS_Calibration_XYZ_Mes_ClearALLButt_Click(object sender, EventArgs e)
        {
            CS_Calib_XYZ_Mes_result_show.Clear();
            CS_Calib_XYZ_Mes_result_show.BackColor = Color.White;

            textBox149.Clear();
            textBox145.Clear();
            textBox144.Clear();
        }

        private void Cs_Get_usr_targetControl_params_Click(object sender, EventArgs e)
        {
            int id;
            Cs_Get_usr_targetControl_params_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;// new GuiBoxArray();
            /*gui.Add(textBox158, 
                    textBox157,
                    cs_UTP_GaamaFacrot_Combo,
                    textBox152,
                    textBox151, 
                    textBox150  
                    );
             * */

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_user_target_control_params_get, Cs_Get_usr_targetControl_params_result_show, gui);
            Monitor.Enter(request_chain);
                id = AllCommands.GetGeneric_ColorSensor("get_user_target_control_params");

            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        }

        private void Cs_Get_usr_targetControl_params_clearAll_Click(object sender, EventArgs e)
        {
            Cs_Get_usr_targetControl_params_result_show.Clear();
            Cs_Get_usr_targetControl_params_result_show.BackColor = Color.White;
            
            /*textBox158.Clear();
            textBox157.Clear();
            //cs_UTP_GaamaFacrot_Combo.Text = strin
            textBox152.Clear();
            textBox151.Clear();
            textBox150.Clear();
            */
        }

       

        private void Cs_Set_usr_targetControl_params_Click(object sender, EventArgs e)
        {
            int id;

            Cs_Get_usr_targetControl_params_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            /*
            gui.Add(textBox21, textBox22);
            */
            command_requestObj obj = null;
            Monitor.Enter(request_chain);
            obj = new command_requestObj(Common.commandType.cmd_cs_user_target_control_params_set, Cs_Get_usr_targetControl_params_result_show, gui);
                id = AllCommands.Set_user_targetControl_data(Convert.ToInt32(textBox158.Text),
                                                        Convert.ToDouble(textBox157.Text),
                                                        cs_UTP_GaamaFacrot_Combo.Text,
                                                        Convert.ToInt32(textBox152.Text) 
                                                        );
                request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }
        

        private void CS_get_white_banalce_butt_Click(object sender, EventArgs e)
        {

            int id;

            Gte_white_balance_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_white_banance_get, Gte_white_balance_result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("get_white_balance");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        }

        private void CS_Set_white_banalce_butt_Click(object sender, EventArgs e)
        {

            int id;
            Gte_white_balance_result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            /*
            gui.Add(textBox21, textBox22);
            */
            command_requestObj obj = null;
            Monitor.Enter(request_chain);
            obj = new command_requestObj(Common.commandType.cmd_cs_white_banance_set, Gte_white_balance_result_show, gui);
            id = AllCommands.Set_white_Balance(Convert.ToDouble(textBox155.Text),
                                                    Convert.ToDouble(textBox154.Text),
                                                    Convert.ToDouble(textBox153.Text)
                                                    );
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_get_white_banalce_butt_clearall_Click(object sender, EventArgs e)
        {
            Gte_white_balance_result_show.Clear();
            Gte_white_balance_result_show.BackColor = Color.White;
            textBox155.Clear();
            textBox154.Clear();
            textBox153.Clear();
        }


        private void cs_tiggher_white_correction_butt_Click(object sender, EventArgs e)
        {

            int id;

            cs_Tigger_white_correction_Result_show.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_tigger_white_correction, cs_Tigger_white_correction_Result_show, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("trigger_white_correction");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void cs_tiggher_white_correction__clearbutt_Click(object sender, EventArgs e)
        {
            cs_Tigger_white_correction_Result_show.Clear();
            cs_Tigger_white_correction_Result_show.BackColor = Color.White;

        }

        

        private void CS_GetCBM_Mode_butt_Click(object sender, EventArgs e)
        {
            int id;

            textBox159.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray(); ;
            gui.Add(cs_cbm_mode_Combo);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_cbm_mode_get, textBox159, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("get_cbm_mode");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_SetCBM_Mode_butt_Click(object sender, EventArgs e)
        {
            int id;

            textBox159.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_cbm_mode_set, textBox159, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Set_cbm_mode(cs_cbm_mode_Combo.Text);
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_GetCBM_Mode_ClearALLbutt_Click(object sender, EventArgs e)
        {
            textBox159.Clear();
            textBox159.BackColor = Color.White;
           

        }

      

        private void CS_sensX_Get_CBM_params_butt_Click(object sender, EventArgs e)
        {
            int id;

            textBox156.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray(); ;
            gui.Add(textBox166,
                    textBox165,
                    textBox164,
                    textBox162,
                    textBox161,
                    textBox160,
                    textBox163);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_cbm_mode_params_get, textBox156, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("get_cbm_native_params");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_sensX_Set_CBM_params_butt_Click(object sender, EventArgs e)
        {
            int id;

            textBox156.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_cbm_mode_params_set, textBox156, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Set_cbm_params(Convert.ToInt32(textBox166.Text),
                                        Convert.ToInt32(textBox165.Text),
                                        Convert.ToInt32(textBox164.Text),
                                        Convert.ToInt32(textBox162.Text),
                                        Convert.ToInt32(textBox161.Text),
                                        Convert.ToInt32(textBox160.Text),
                                        Convert.ToInt32(textBox163.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_sensX_Get_CBM_params_ClearAllbutt_Click(object sender, EventArgs e)
        {
            textBox156.Clear();
            textBox156.BackColor = Color.White;
            textBox166.Clear();
            textBox165.Clear();
            textBox164.Clear();
            textBox162.Clear();
            textBox161.Clear();
            textBox160.Clear();
            textBox163.Clear();

        }

        private void Cs_Black_level_Get_butt_Click(object sender, EventArgs e)
        {
            int id;

            textBox171.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray(); ;
            gui.Add(textBox170);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_black_level_get, textBox171, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("get_black_level");
            request_chain[id] = obj;


            gui = new GuiBoxArray(); ;
            gui.Add(textBox168);
            obj = new command_requestObj(Common.commandType.cmd_cs_white_level_get, textBox171, gui);

            id = AllCommands.GetGeneric_ColorSensor("get_white_level");
            request_chain[id] = obj;
           
            Monitor.Exit(request_chain);

           


        }

        private void Cs_Black_level_Set_butt_Click(object sender, EventArgs e)
        {
            int id;

            textBox171.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_black_level_set, textBox171, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Set_BlackWhite_level("set_black_level", Convert.ToInt32(textBox170.Text));
            request_chain[id] = obj;
            
            obj = new command_requestObj(Common.commandType.cmd_cs_white_level_set, textBox171, gui);
            
            id = AllCommands.Set_BlackWhite_level("set_white_level", Convert.ToInt32(textBox168.Text));
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Cs_Black_level_ClearAll_butt_Click(object sender, EventArgs e)
        {
            textBox171.Clear();
            textBox171.BackColor = Color.White;
            textBox170.Clear();
            textBox168.Clear();
        }

        private void CS_MinMax_brightness_get_Click(object sender, EventArgs e)
        {
            int id;

            textBox173.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray(); ;
            gui.Add(textBox172, textBox169);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_max_min_brightness_get, textBox173, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("max_min_brightness");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_MinMax_brightness_get_clearAll_Click(object sender, EventArgs e)
        {
            textBox171.Clear();
            textBox171.BackColor = Color.White;
        }

       

        private void Cs_Get_eror_info_get_Click(object sender, EventArgs e)
        {
            int id;

            textBox181.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray(); ;
            gui.Add(textBox180,
                    textBox179,
                    textBox178,
                    textBox176,
                    textBox175);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_gobal_error_info_get, textBox181, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_ColorSensor("get_status_err_info");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void Cs_Get_eror_info_ClearALl_Click(object sender, EventArgs e)
        {
            textBox181.Clear();
            textBox181.BackColor = Color.White;

        }

        
        #endregion

        private void CS_Barco_gama_set_butt_Click(object sender, EventArgs e)
        {
            int id;

            textBox182.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_barco_gama_set, textBox182, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("upload_barco_gamma");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        }

        private void CS_Barco_gama_set_ClearALLbutt_Click(object sender, EventArgs e)
        {

        }

        private void Mo_getLogFile_butt_Click(object sender, EventArgs e)
        {
            int id;

            MO_LogMessages_richBox.Clear();
            textBox174.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_get_log_msg_count_internal, textBox174, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_logmsg_count");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
            

            /*
            textBox174.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_get_log_msg_internal, textBox174, gui);
            obj.linenum = 1;
            
            Monitor.Enter(request_chain);
            id = AllCommands.GetLogMessage("1");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
             * */

        }

        private void MO_Clear_Lo_Msgs_Click(object sender, EventArgs e)
        {
            MO_LogMessages_richBox.Clear();
        }

        private void Mo_Log_msg_UnDo_Click(object sender, EventArgs e)
        {
            MO_LogMessages_richBox.Undo();
        }

        private void GetDiagnostics()
        {
            MO_DiagnosticsMessages_richBox.Clear();
            int id;

            textBox177.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_tigger_Diagnostics, textBox177, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("trigger_auto_diagnosis");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);
        
        }

        private void GetDiagnostics_count()
        {
            int id;

            textBox177.BackColor = Color.HotPink;
            GuiBoxArray gui = null;
            //gui.Add(textBox155, textBox154, textBox153);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_Get_Diagnostics_count_get, textBox177, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_diagnosis_result_count");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void mo_Get_diagnostics_butt_Click(object sender, EventArgs e)
        {
            
            GetDiagnostics();
        }

        private void mo_Get_diagnostics_butt_clear_Click(object sender, EventArgs e)
        {
            MO_DiagnosticsMessages_richBox.Clear();
        }

        private void mo_Get_diagnostics_Undo_butt_Click(object sender, EventArgs e)
        {
            MO_DiagnosticsMessages_richBox.Undo();
        }

        private void Monitoring_GetFanTicks_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox184.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox185);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_mo_get_fan_ticks, textBox184, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetFanTicks("fan1");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


            gui = new GuiBoxArray();
            gui.Add(textBox183);
            obj = new command_requestObj(Common.commandType.cmd_mo_get_fan_ticks, textBox184, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetFanTicks("fan2");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_Gaama_status_get_Click(object sender, EventArgs e)
        {
            int id;
            textBox187.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox186);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_cs_gaam_upload_status_get, textBox187, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.GetGeneric_SysMgr("get_barco_gamma_upload_sts");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void CS_GaamA_Status_ClearALL_Click(object sender, EventArgs e)
        {
            textBox187.Clear();
            textBox187.BackColor = Color.White;
            textBox186.Clear();
        }

        private void img_Get_clock_status_Click(object sender, EventArgs e)
        {
            int id;
            textBox188.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox189);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_clock_status_get, textBox188, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_clock_status("dvi1");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


            gui = new GuiBoxArray();
            gui.Add(textBox190);
            obj = new command_requestObj(Common.commandType.cmd_img_clock_status_get, textBox188, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_clock_status("dvi2");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

            gui = new GuiBoxArray();
            gui.Add(textBox191);
            obj = new command_requestObj(Common.commandType.cmd_img_clock_status_get, textBox188, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_clock_status("hdmi");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


            gui = new GuiBoxArray();
            gui.Add(textBox194);
            obj = new command_requestObj(Common.commandType.cmd_img_clock_status_get, textBox188, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_clock_status("dp");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

            gui = new GuiBoxArray();
            gui.Add(textBox193);
            obj = new command_requestObj(Common.commandType.cmd_img_clock_status_get, textBox188, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_clock_status("ops");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

            gui = new GuiBoxArray();
            gui.Add(textBox192);
            obj = new command_requestObj(Common.commandType.cmd_img_clock_status_get, textBox188, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_clock_status("onboard");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        }

        private void img_Get_clock_Status_clearAll_Click(object sender, EventArgs e)
        {
            textBox188.Clear();
            textBox188.BackColor = Color.White;
            textBox189.Clear();
            textBox190.Clear();
            textBox191.Clear();
            textBox194.Clear();
            textBox193.Clear();
            textBox192.Clear();


        }

        private void img_Get_scm_status_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox201.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox199);
            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_scm_status_get, textBox201, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_scm_status("scm0");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

            textBox201.BackColor = Color.HotPink;
             gui = new GuiBoxArray();
             gui.Add(textBox195);
             obj = new command_requestObj(Common.commandType.cmd_img_scm_status_get, textBox201, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_scm_status("scm1");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

        }

        private void img_Get_scm_status_butt_clearAll_Click(object sender, EventArgs e)
        {
            textBox201.Clear();
            textBox201.BackColor = Color.White;
            textBox199.Clear();
            textBox195.Clear();



        }

        private void img_Wall_GeO_status_Get_butt_Click(object sender, EventArgs e)
        {
            int id;
            textBox202.BackColor = Color.HotPink;
            GuiBoxArray gui = new GuiBoxArray();
            gui.Add(textBox200,
                    textBox198,
                    textBox197,
                    textBox196,
                    textBox204,
                    textBox203);

            command_requestObj obj = new command_requestObj(Common.commandType.cmd_img_wall_config_status_get, textBox202, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_wall_status("scm0");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);

            gui = new GuiBoxArray();
            gui.Add(textBox208,
                    textBox209,
                    textBox210,
                    textBox205,
                    textBox207,
                    textBox206);

            obj = new command_requestObj(Common.commandType.cmd_img_wall_config_status_get, textBox202, gui);
            Monitor.Enter(request_chain);
            id = AllCommands.Get_wall_status("scm1");
            request_chain[id] = obj;
            Monitor.Exit(request_chain);


        }

        private void img_Wall_GeO_status_Get_butt_clearAll_Click(object sender, EventArgs e)
        {
            textBox202.Clear();
            textBox202.BackColor = Color.White;
            textBox200.Clear();
            textBox198.Clear();
            textBox197.Clear();
            textBox196.Clear();
            textBox204.Clear();
            textBox203.Clear();

            textBox208.Clear();
            textBox209.Clear();
            textBox210.Clear();
            textBox205.Clear();
            textBox207.Clear();
            textBox206.Clear();


        }

        private void KortexGuiMain_Resize(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized && bTrayMiniMaize)
            {

                this.Hide();
                notifyIcon1.Visible = true;
                /*notifyIcon1.Visible = true;
                notifyIcon1.ShowBalloonTip(3000);
                this.ShowInTaskbar = false;
                 * */
            }
            
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
            /*this.WindowState = FormWindowState.Normal;
            this.ShowInTaskbar = true;
            notifyIcon1.Visible = false;
            */
        }



        



        



    }
}








